diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2020-08-31 12:33:43 -0600 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2020-08-31 12:33:43 -0600 |
commit | 494032584436338896cd275d7563bc7b325cd1c4 (patch) | |
tree | 606be03a2280a03d7e3da33301895abc8a717d84 | |
parent | 744d04c2585d50f64cf3d43d139c310a18e78f73 (diff) |
fileserver: Fix inconsistencies in browse JSON
-rw-r--r-- | modules/caddyhttp/fileserver/browse_test.go | 36 | ||||
-rw-r--r-- | modules/caddyhttp/fileserver/browselisting.go | 32 |
2 files changed, 34 insertions, 34 deletions
diff --git a/modules/caddyhttp/fileserver/browse_test.go b/modules/caddyhttp/fileserver/browse_test.go index b1f7092..5d5874f 100644 --- a/modules/caddyhttp/fileserver/browse_test.go +++ b/modules/caddyhttp/fileserver/browse_test.go @@ -11,15 +11,15 @@ func BenchmarkBrowseWriteJSON(b *testing.B) { fsrv := new(FileServer) fsrv.Provision(caddy.Context{}) listing := browseListing{ - Name: "test", - Path: "test", - CanGoUp: false, - Items: make([]fileInfo, 100), - NumDirs: 42, - NumFiles: 420, - Sort: "", - Order: "", - ItemsLimitedTo: 42, + Name: "test", + Path: "test", + CanGoUp: false, + Items: make([]fileInfo, 100), + NumDirs: 42, + NumFiles: 420, + Sort: "", + Order: "", + Limit: 42, } b.ResetTimer() @@ -36,15 +36,15 @@ func BenchmarkBrowseWriteHTML(b *testing.B) { template: template.New("test"), } listing := browseListing{ - Name: "test", - Path: "test", - CanGoUp: false, - Items: make([]fileInfo, 100), - NumDirs: 42, - NumFiles: 420, - Sort: "", - Order: "", - ItemsLimitedTo: 42, + Name: "test", + Path: "test", + CanGoUp: false, + Items: make([]fileInfo, 100), + NumDirs: 42, + NumFiles: 420, + Sort: "", + Order: "", + Limit: 42, } b.ResetTimer() diff --git a/modules/caddyhttp/fileserver/browselisting.go b/modules/caddyhttp/fileserver/browselisting.go index cebfe8f..79944f9 100644 --- a/modules/caddyhttp/fileserver/browselisting.go +++ b/modules/caddyhttp/fileserver/browselisting.go @@ -76,34 +76,34 @@ func (fsrv *FileServer) directoryListing(files []os.FileInfo, canGoUp bool, urlP type browseListing struct { // The name of the directory (the last element of the path). - Name string + Name string `json:"name"` // The full path of the request. - Path string + Path string `json:"path"` // Whether the parent directory is browseable. - CanGoUp bool + CanGoUp bool `json:"can_go_up"` // The items (files and folders) in the path. - Items []fileInfo + Items []fileInfo `json:"items,omitempty"` + + // If ≠0 then Items starting from that many elements. + 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 + NumDirs int `json:"num_dirs"` // The number of files (items that aren't directories) in the listing. - NumFiles int + NumFiles int `json:"num_files"` // Sort column used - Sort string + Sort string `json:"sort,omitempty"` // 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. - ItemOffset int + Order string `json:"order,omitempty"` } // Breadcrumbs returns l.Path where every element maps @@ -166,7 +166,7 @@ func (l *browseListing) applySortAndLimit(sortParam, orderParam, limitParam stri offset, _ := strconv.Atoi(offsetParam) if offset > 0 && offset <= len(l.Items) { 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) { l.Items = l.Items[:limit] - l.ItemsLimitedTo = limit + l.Limit = limit } } } |