mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-22 13:29:01 +08:00
fileserver: New file browse template (#5427)
* fileserver: New file browse template * Redo extension/icon logic; minor color tweaks * Fine-tune image display
This commit is contained in:
parent
9e943319b4
commit
6cc3cbbc69
|
@ -152,12 +152,20 @@ func (fsrv *FileServer) loadDirectoryContents(ctx context.Context, dir fs.ReadDi
|
|||
// browseApplyQueryParams applies query parameters to the listing.
|
||||
// It mutates the listing and may set cookies.
|
||||
func (fsrv *FileServer) browseApplyQueryParams(w http.ResponseWriter, r *http.Request, listing *browseTemplateContext) {
|
||||
layoutParam := r.URL.Query().Get("layout")
|
||||
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 layoutParam {
|
||||
case "list", "grid", "":
|
||||
listing.Layout = layoutParam
|
||||
default:
|
||||
listing.Layout = "list"
|
||||
}
|
||||
|
||||
// figure out what to sort by
|
||||
switch sortParam {
|
||||
case "":
|
||||
sortParam = sortByNameDirFirst
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -134,6 +134,9 @@ type browseTemplateContext struct {
|
|||
|
||||
// Sorting order
|
||||
Order string `json:"order,omitempty"`
|
||||
|
||||
// Display format (list or grid)
|
||||
Layout string `json:"layout,omitempty"`
|
||||
}
|
||||
|
||||
// Breadcrumbs returns l.Path where every element maps
|
||||
|
@ -229,6 +232,16 @@ type fileInfo struct {
|
|||
IsSymlink bool `json:"is_symlink"`
|
||||
}
|
||||
|
||||
// HasExt returns true if the filename has any of the given suffixes, case-insensitive.
|
||||
func (fi fileInfo) HasExt(exts ...string) bool {
|
||||
for _, ext := range exts {
|
||||
if strings.HasSuffix(strings.ToLower(fi.Name), strings.ToLower(ext)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// HumanSize returns the size of the file as a
|
||||
// human-readable string in IEC format (i.e.
|
||||
// power of 2 or base 1024).
|
||||
|
|
Loading…
Reference in New Issue
Block a user