mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
866375141f
Former-commit-id: 5daa76063fbd8766115a722336d544d2f6156c74 [formerly 3d644f06b38b6c20f5549b3f2f780556881f216e] [formerly beb819187116079ce83329e85bb1b1d5e6b908ea [formerly 73e0acaa71
]]
Former-commit-id: 01dfc4bb6016d6c3de2bb932695e7ca6b9185ff6 [formerly cdee480885c5050d9311f41f39ef7b4feefcc602]
Former-commit-id: 82bbfed106ddae78f22d01cabc11f314c19a1796
65 lines
2.7 KiB
Go
65 lines
2.7 KiB
Go
package http
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/filebrowser/filebrowser/v2/settings"
|
|
"github.com/filebrowser/filebrowser/v2/storage"
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
type modifyRequest struct {
|
|
What string `json:"what"` // Answer to: what data type?
|
|
Which []string `json:"which"` // Answer to: which fields?
|
|
}
|
|
|
|
func NewHandler(storage *storage.Storage, server *settings.Server) (http.Handler, error) {
|
|
server.Clean()
|
|
|
|
r := mux.NewRouter()
|
|
index, static := getStaticHandlers(storage, server)
|
|
|
|
monkey := func(fn handleFunc, prefix string) http.Handler {
|
|
return handle(fn, prefix, storage, server)
|
|
}
|
|
|
|
r.PathPrefix("/static").Handler(static)
|
|
r.NotFoundHandler = index
|
|
|
|
api := r.PathPrefix("/api").Subrouter()
|
|
|
|
api.Handle("/login", monkey(loginHandler, ""))
|
|
api.Handle("/signup", monkey(signupHandler, ""))
|
|
api.Handle("/renew", monkey(renewHandler, ""))
|
|
|
|
users := api.PathPrefix("/users").Subrouter()
|
|
users.Handle("", monkey(usersGetHandler, "")).Methods("GET")
|
|
users.Handle("", monkey(userPostHandler, "")).Methods("POST")
|
|
users.Handle("/{id:[0-9]+}", monkey(userPutHandler, "")).Methods("PUT")
|
|
users.Handle("/{id:[0-9]+}", monkey(userGetHandler, "")).Methods("GET")
|
|
users.Handle("/{id:[0-9]+}", monkey(userDeleteHandler, "")).Methods("DELETE")
|
|
|
|
api.PathPrefix("/resources").Handler(monkey(resourceGetHandler, "/api/resources")).Methods("GET")
|
|
api.PathPrefix("/resources").Handler(monkey(resourceDeleteHandler, "/api/resources")).Methods("DELETE")
|
|
api.PathPrefix("/resources").Handler(monkey(resourcePostPutHandler, "/api/resources")).Methods("POST")
|
|
api.PathPrefix("/resources").Handler(monkey(resourcePostPutHandler, "/api/resources")).Methods("PUT")
|
|
api.PathPrefix("/resources").Handler(monkey(resourcePatchHandler, "/api/resources")).Methods("PATCH")
|
|
|
|
api.PathPrefix("/share").Handler(monkey(shareGetsHandler, "/api/share")).Methods("GET")
|
|
api.PathPrefix("/share").Handler(monkey(sharePostHandler, "/api/share")).Methods("POST")
|
|
api.PathPrefix("/share").Handler(monkey(shareDeleteHandler, "/api/share")).Methods("DELETE")
|
|
|
|
api.Handle("/settings", monkey(settingsGetHandler, "")).Methods("GET")
|
|
api.Handle("/settings", monkey(settingsPutHandler, "")).Methods("PUT")
|
|
|
|
api.PathPrefix("/raw").Handler(monkey(rawHandler, "/api/raw")).Methods("GET")
|
|
api.PathPrefix("/command").Handler(monkey(commandsHandler, "/api/command")).Methods("GET")
|
|
api.PathPrefix("/search").Handler(monkey(searchHandler, "/api/search")).Methods("GET")
|
|
|
|
public := api.PathPrefix("/public").Subrouter()
|
|
public.PathPrefix("/dl").Handler(monkey(publicDlHandler, "/api/public/dl/")).Methods("GET")
|
|
public.PathPrefix("/share").Handler(monkey(publicShareHandler, "/api/public/share/")).Methods("GET")
|
|
|
|
return http.StripPrefix(server.BaseURL, r), nil
|
|
}
|