mirror of
https://github.com/caddyserver/caddy.git
synced 2025-02-24 00:38:53 +01: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
3 changed files with 663 additions and 194 deletions
|
@ -152,12 +152,20 @@ func (fsrv *FileServer) loadDirectoryContents(ctx context.Context, dir fs.ReadDi
|
||||||
// browseApplyQueryParams applies query parameters to the listing.
|
// browseApplyQueryParams applies query parameters to the listing.
|
||||||
// It mutates the listing and may set cookies.
|
// It mutates the listing and may set cookies.
|
||||||
func (fsrv *FileServer) browseApplyQueryParams(w http.ResponseWriter, r *http.Request, listing *browseTemplateContext) {
|
func (fsrv *FileServer) browseApplyQueryParams(w http.ResponseWriter, r *http.Request, listing *browseTemplateContext) {
|
||||||
|
layoutParam := r.URL.Query().Get("layout")
|
||||||
sortParam := r.URL.Query().Get("sort")
|
sortParam := r.URL.Query().Get("sort")
|
||||||
orderParam := r.URL.Query().Get("order")
|
orderParam := r.URL.Query().Get("order")
|
||||||
limitParam := r.URL.Query().Get("limit")
|
limitParam := r.URL.Query().Get("limit")
|
||||||
offsetParam := r.URL.Query().Get("offset")
|
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 {
|
switch sortParam {
|
||||||
case "":
|
case "":
|
||||||
sortParam = sortByNameDirFirst
|
sortParam = sortByNameDirFirst
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -134,6 +134,9 @@ type browseTemplateContext struct {
|
||||||
|
|
||||||
// Sorting order
|
// Sorting order
|
||||||
Order string `json:"order,omitempty"`
|
Order string `json:"order,omitempty"`
|
||||||
|
|
||||||
|
// Display format (list or grid)
|
||||||
|
Layout string `json:"layout,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Breadcrumbs returns l.Path where every element maps
|
// Breadcrumbs returns l.Path where every element maps
|
||||||
|
@ -229,6 +232,16 @@ type fileInfo struct {
|
||||||
IsSymlink bool `json:"is_symlink"`
|
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
|
// HumanSize returns the size of the file as a
|
||||||
// human-readable string in IEC format (i.e.
|
// human-readable string in IEC format (i.e.
|
||||||
// power of 2 or base 1024).
|
// power of 2 or base 1024).
|
||||||
|
|
Loading…
Reference in a new issue