diff --git a/modules/caddyhttp/fileserver/browse.go b/modules/caddyhttp/fileserver/browse.go index e5e137fc..3fecad95 100644 --- a/modules/caddyhttp/fileserver/browse.go +++ b/modules/caddyhttp/fileserver/browse.go @@ -106,6 +106,7 @@ func (fsrv *FileServer) browseApplyQueryParams(w http.ResponseWriter, r *http.Re sortParam := r.URL.Query().Get("sort") orderParam := r.URL.Query().Get("order") limitParam := r.URL.Query().Get("limit") + offsetParam := r.URL.Query().Get("offset") // first figure out what to sort by switch sortParam { @@ -130,7 +131,7 @@ func (fsrv *FileServer) browseApplyQueryParams(w http.ResponseWriter, r *http.Re } // finally, apply the sorting and limiting - listing.applySortAndLimit(sortParam, orderParam, limitParam) + listing.applySortAndLimit(sortParam, orderParam, limitParam, offsetParam) } func (fsrv *FileServer) browseWriteJSON(listing browseListing) (*bytes.Buffer, error) { diff --git a/modules/caddyhttp/fileserver/browselisting.go b/modules/caddyhttp/fileserver/browselisting.go index 9c7c4a20..cebfe8fd 100644 --- a/modules/caddyhttp/fileserver/browselisting.go +++ b/modules/caddyhttp/fileserver/browselisting.go @@ -101,6 +101,9 @@ type browseListing struct { // If ≠0 then Items have been limited to that many elements. ItemsLimitedTo int + + // If ≠0 then Items starting from that many elements. + ItemOffset int } // Breadcrumbs returns l.Path where every element maps @@ -131,7 +134,7 @@ func (l browseListing) Breadcrumbs() []crumb { return result } -func (l *browseListing) applySortAndLimit(sortParam, orderParam, limitParam string) { +func (l *browseListing) applySortAndLimit(sortParam, orderParam, limitParam string, offsetParam string) { l.Sort = sortParam l.Order = orderParam @@ -159,8 +162,17 @@ func (l *browseListing) applySortAndLimit(sortParam, orderParam, limitParam stri } } + if offsetParam != "" { + offset, _ := strconv.Atoi(offsetParam) + if offset > 0 && offset <= len(l.Items) { + l.Items = l.Items[offset:] + l.ItemOffset = offset + } + } + if limitParam != "" { limit, _ := strconv.Atoi(limitParam) + if limit > 0 && limit <= len(l.Items) { l.Items = l.Items[:limit] l.ItemsLimitedTo = limit diff --git a/modules/caddyhttp/fileserver/browsetpl.go b/modules/caddyhttp/fileserver/browsetpl.go index 567e8dd7..6415d59e 100644 --- a/modules/caddyhttp/fileserver/browsetpl.go +++ b/modules/caddyhttp/fileserver/browsetpl.go @@ -296,37 +296,37 @@ footer {