mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
4071a58107
Former-commit-id: e2d0b723963d3a82ac0f9042280885e800b1132a [formerly e1ae3f4da43f0481a57c39f11735c36b33fda857] [formerly 02ab5f5fb5f4b812cf413ebc923b853d4f0b4afb [formerly 83bc555094
]]
Former-commit-id: bee2ec30c9aa9619a69eaa6320822f8525a41535 [formerly 1af59077494b5e8674af547d0361f50a2ecf8f26]
Former-commit-id: 573870f4a6bffcee3e48fbc0b8349402eaeba407
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package jekyll
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/hacdias/filemanager"
|
|
"github.com/hacdias/filemanager/caddy/parser"
|
|
"github.com/mholt/caddy"
|
|
"github.com/mholt/caddy/caddyhttp/httpserver"
|
|
)
|
|
|
|
func init() {
|
|
caddy.RegisterPlugin("jekyll", caddy.Plugin{
|
|
ServerType: "http",
|
|
Action: setup,
|
|
})
|
|
}
|
|
|
|
type plugin struct {
|
|
Next httpserver.Handler
|
|
Configs []*filemanager.FileManager
|
|
}
|
|
|
|
// ServeHTTP determines if the request is for this plugin, and if all prerequisites are met.
|
|
func (f plugin) 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
|
|
}
|
|
|
|
f.Configs[i].ServeHTTP(w, r)
|
|
return 0, nil
|
|
}
|
|
|
|
return f.Next.ServeHTTP(w, r)
|
|
}
|
|
|
|
// setup configures a new FileManager middleware instance.
|
|
func setup(c *caddy.Controller) error {
|
|
configs, err := parser.Parse(c, "jekyll")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
|
|
return plugin{Configs: configs, Next: next}
|
|
})
|
|
|
|
return nil
|
|
}
|