mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-10-26 11:04:10 +00:00 
			
		
		
		
	fileserver: Fix inconsistencies in browse JSON
This commit is contained in:
		
							parent
							
								
									744d04c258
								
							
						
					
					
						commit
						4940325844
					
				
					 2 changed files with 40 additions and 40 deletions
				
			
		|  | @ -19,7 +19,7 @@ func BenchmarkBrowseWriteJSON(b *testing.B) { | ||||||
| 		NumFiles: 420, | 		NumFiles: 420, | ||||||
| 		Sort:     "", | 		Sort:     "", | ||||||
| 		Order:    "", | 		Order:    "", | ||||||
| 		ItemsLimitedTo: 42, | 		Limit:    42, | ||||||
| 	} | 	} | ||||||
| 	b.ResetTimer() | 	b.ResetTimer() | ||||||
| 
 | 
 | ||||||
|  | @ -44,7 +44,7 @@ func BenchmarkBrowseWriteHTML(b *testing.B) { | ||||||
| 		NumFiles: 420, | 		NumFiles: 420, | ||||||
| 		Sort:     "", | 		Sort:     "", | ||||||
| 		Order:    "", | 		Order:    "", | ||||||
| 		ItemsLimitedTo: 42, | 		Limit:    42, | ||||||
| 	} | 	} | ||||||
| 	b.ResetTimer() | 	b.ResetTimer() | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -76,34 +76,34 @@ func (fsrv *FileServer) directoryListing(files []os.FileInfo, canGoUp bool, urlP | ||||||
| 
 | 
 | ||||||
| type browseListing struct { | type browseListing struct { | ||||||
| 	// The name of the directory (the last element of the path). | 	// The name of the directory (the last element of the path). | ||||||
| 	Name string | 	Name string `json:"name"` | ||||||
| 
 | 
 | ||||||
| 	// The full path of the request. | 	// The full path of the request. | ||||||
| 	Path string | 	Path string `json:"path"` | ||||||
| 
 | 
 | ||||||
| 	// Whether the parent directory is browseable. | 	// Whether the parent directory is browseable. | ||||||
| 	CanGoUp bool | 	CanGoUp bool `json:"can_go_up"` | ||||||
| 
 | 
 | ||||||
| 	// The items (files and folders) in the path. | 	// The items (files and folders) in the path. | ||||||
| 	Items []fileInfo | 	Items []fileInfo `json:"items,omitempty"` | ||||||
| 
 |  | ||||||
| 	// The number of directories in the listing. |  | ||||||
| 	NumDirs int |  | ||||||
| 
 |  | ||||||
| 	// The number of files (items that aren't directories) in the listing. |  | ||||||
| 	NumFiles int |  | ||||||
| 
 |  | ||||||
| 	// Sort column used |  | ||||||
| 	Sort string |  | ||||||
| 
 |  | ||||||
| 	// Sorting order |  | ||||||
| 	Order string |  | ||||||
| 
 |  | ||||||
| 	// If ≠0 then Items have been limited to that many elements. |  | ||||||
| 	ItemsLimitedTo int |  | ||||||
| 
 | 
 | ||||||
| 	// If ≠0 then Items starting from that many elements. | 	// If ≠0 then Items starting from that many elements. | ||||||
| 	ItemOffset int | 	Offset int `json:"offset,omitempty"` | ||||||
|  | 
 | ||||||
|  | 	// If ≠0 then Items have been limited to that many elements. | ||||||
|  | 	Limit int `json:"limit,omitempty"` | ||||||
|  | 
 | ||||||
|  | 	// The number of directories in the listing. | ||||||
|  | 	NumDirs int `json:"num_dirs"` | ||||||
|  | 
 | ||||||
|  | 	// The number of files (items that aren't directories) in the listing. | ||||||
|  | 	NumFiles int `json:"num_files"` | ||||||
|  | 
 | ||||||
|  | 	// Sort column used | ||||||
|  | 	Sort string `json:"sort,omitempty"` | ||||||
|  | 
 | ||||||
|  | 	// Sorting order | ||||||
|  | 	Order string `json:"order,omitempty"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Breadcrumbs returns l.Path where every element maps | // Breadcrumbs returns l.Path where every element maps | ||||||
|  | @ -166,7 +166,7 @@ func (l *browseListing) applySortAndLimit(sortParam, orderParam, limitParam stri | ||||||
| 		offset, _ := strconv.Atoi(offsetParam) | 		offset, _ := strconv.Atoi(offsetParam) | ||||||
| 		if offset > 0 && offset <= len(l.Items) { | 		if offset > 0 && offset <= len(l.Items) { | ||||||
| 			l.Items = l.Items[offset:] | 			l.Items = l.Items[offset:] | ||||||
| 			l.ItemOffset = offset | 			l.Offset = offset | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -175,7 +175,7 @@ func (l *browseListing) applySortAndLimit(sortParam, orderParam, limitParam stri | ||||||
| 
 | 
 | ||||||
| 		if limit > 0 && limit <= len(l.Items) { | 		if limit > 0 && limit <= len(l.Items) { | ||||||
| 			l.Items = l.Items[:limit] | 			l.Items = l.Items[:limit] | ||||||
| 			l.ItemsLimitedTo = limit | 			l.Limit = limit | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Matthew Holt
						Matthew Holt