mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-05-09 11:42:57 +00:00

Former-commit-id: d177c7aec04c7ae390dff16360967b1d661a69d7 [formerly 31e74c5f6cde8bb35883900f5b7d4bce2e93021b] [formerly 3789391771bf37cd60492f99373e64c2946af7a8 [formerly ff55952f927418618996771144721b59687bbcd7]] Former-commit-id: 22b6c4955dd71b9b08f80a86612934037d6f04ce [formerly 81712fea81d3ff1b1370682111b30f1d66215277] Former-commit-id: b8b586892b2f23e9293f167bbf209b537d5e43b2
33 lines
934 B
Go
33 lines
934 B
Go
// Package filemanager provides middleware for managing files in a directory
|
|
// when directory path is requested instead of a specific file. Based on browse
|
|
// middleware.
|
|
package filemanager
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/hacdias/filemanager"
|
|
"github.com/mholt/caddy/caddyhttp/httpserver"
|
|
)
|
|
|
|
// FileManager is an http.Handler that can show a file listing when
|
|
// directories in the given paths are specified.
|
|
type FileManager struct {
|
|
Next httpserver.Handler
|
|
Configs []*filemanager.FileManager
|
|
}
|
|
|
|
// ServeHTTP determines if the request is for this plugin, and if all prerequisites are met.
|
|
func (f FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
|
|
for i := range f.Configs {
|
|
// Checks if this Path should be handled by File Manager.
|
|
if !httpserver.Path(r.URL.Path).Matches(f.Configs[i].BaseURL) {
|
|
continue
|
|
}
|
|
|
|
return f.Configs[i].ServeHTTP(w, r)
|
|
}
|
|
|
|
return f.Next.ServeHTTP(w, r)
|
|
}
|