@marcel91200 / caddy Mirror · read-only / commits / 49403258
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

fileserver: Fix inconsistencies in browse JSON

Matthew Holt committed Aug 31, 2020 at 12:33 UTC 494032584436338896cd275d7563bc7b325cd1c4
2 files changed +34 -34
modules/caddyhttp/fileserver/browse_test.go
+18 -18
@@ -11,15 +11,15 @@ func BenchmarkBrowseWriteJSON(b *testing.B) {
11 fsrv := new(FileServer)
12 fsrv.Provision(caddy.Context{})
13 listing := browseListing{
14 - Name: "test",
15 - Path: "test",
16 - CanGoUp: false,
17 - Items: make([]fileInfo, 100),
18 - NumDirs: 42,
19 - NumFiles: 420,
20 - Sort: "",
21 - Order: "",
22 - ItemsLimitedTo: 42,
14 + Name: "test",
15 + Path: "test",
16 + CanGoUp: false,
17 + Items: make([]fileInfo, 100),
18 + NumDirs: 42,
19 + NumFiles: 420,
20 + Sort: "",
21 + Order: "",
22 + Limit: 42,
23 }
24 b.ResetTimer()
25
@@ -36,15 +36,15 @@ func BenchmarkBrowseWriteHTML(b *testing.B) {
36 template: template.New("test"),
37 }
38 listing := browseListing{
39 - Name: "test",
40 - Path: "test",
41 - CanGoUp: false,
42 - Items: make([]fileInfo, 100),
43 - NumDirs: 42,
44 - NumFiles: 420,
45 - Sort: "",
46 - Order: "",
47 - ItemsLimitedTo: 42,
39 + Name: "test",
40 + Path: "test",
41 + CanGoUp: false,
42 + Items: make([]fileInfo, 100),
43 + NumDirs: 42,
44 + NumFiles: 420,
45 + Sort: "",
46 + Order: "",
47 + Limit: 42,
48 }
49 b.ResetTimer()
50
modules/caddyhttp/fileserver/browselisting.go
+16 -16
@@ -76,34 +76,34 @@ func (fsrv *FileServer) directoryListing(files []os.FileInfo, canGoUp bool, urlP
76
77 type browseListing struct {
78 // The name of the directory (the last element of the path).
79 - Name string
79 + Name string `json:"name"`
80
81 // The full path of the request.
82 - Path string
82 + Path string `json:"path"`
83
84 // Whether the parent directory is browseable.
85 - CanGoUp bool
85 + CanGoUp bool `json:"can_go_up"`
86
87 // The items (files and folders) in the path.
88 - Items []fileInfo
88 + Items []fileInfo `json:"items,omitempty"`
89 +
90 + // If ≠0 then Items starting from that many elements.
91 + Offset int `json:"offset,omitempty"`
92 +
93 + // If ≠0 then Items have been limited to that many elements.
94 + Limit int `json:"limit,omitempty"`
95
96 // The number of directories in the listing.
91 - NumDirs int
97 + NumDirs int `json:"num_dirs"`
98
99 // The number of files (items that aren't directories) in the listing.
94 - NumFiles int
100 + NumFiles int `json:"num_files"`
101
102 // Sort column used
97 - Sort string
103 + Sort string `json:"sort,omitempty"`
104
105 // Sorting order
100 - Order string
101 -
102 - // If ≠0 then Items have been limited to that many elements.
103 - ItemsLimitedTo int
104 -
105 - // If ≠0 then Items starting from that many elements.
106 - ItemOffset int
106 + Order string `json:"order,omitempty"`
107 }
108
109 // Breadcrumbs returns l.Path where every element maps
@@ -166,7 +166,7 @@ func (l *browseListing) applySortAndLimit(sortParam, orderParam, limitParam stri
166 offset, _ := strconv.Atoi(offsetParam)
167 if offset > 0 && offset <= len(l.Items) {
168 l.Items = l.Items[offset:]
169 - l.ItemOffset = offset
169 + l.Offset = offset
170 }
171 }
172
@@ -175,7 +175,7 @@ func (l *browseListing) applySortAndLimit(sortParam, orderParam, limitParam stri
175
176 if limit > 0 && limit <= len(l.Items) {
177 l.Items = l.Items[:limit]
178 - l.ItemsLimitedTo = limit
178 + l.Limit = limit
179 }
180 }
181 }