2019-01-05 22:44:33 +00:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2019-01-08 10:29:09 +00:00
|
|
|
"github.com/filebrowser/filebrowser/v2/settings"
|
2019-01-05 22:44:33 +00:00
|
|
|
"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?
|
|
|
|
}
|
|
|
|
|
2019-01-08 10:29:09 +00:00
|
|
|
func NewHandler(storage *storage.Storage, server *settings.Server) (http.Handler, error) {
|
2019-01-05 22:44:33 +00:00
|
|
|
r := mux.NewRouter()
|
|
|
|
|
2019-01-08 10:29:09 +00:00
|
|
|
index, static := getStaticHandlers(storage, server)
|
|
|
|
|
|
|
|
monkey := func(fn handleFunc, prefix string) http.Handler {
|
|
|
|
return handle(fn, prefix, storage, server)
|
|
|
|
}
|
2019-01-05 22:44:33 +00:00
|
|
|
|
|
|
|
r.PathPrefix("/static").Handler(static)
|
|
|
|
r.NotFoundHandler = index
|
|
|
|
|
|
|
|
api := r.PathPrefix("/api").Subrouter()
|
|
|
|
|
2019-01-08 10:29:09 +00:00
|
|
|
api.Handle("/login", monkey(loginHandler, ""))
|
|
|
|
api.Handle("/signup", monkey(signupHandler, ""))
|
|
|
|
api.Handle("/renew", monkey(renewHandler, ""))
|
2019-01-05 22:44:33 +00:00
|
|
|
|
|
|
|
users := api.PathPrefix("/users").Subrouter()
|
2019-01-08 10:29:09 +00:00
|
|
|
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")
|
2019-01-05 22:44:33 +00:00
|
|
|
|
2019-01-08 10:29:09 +00:00
|
|
|
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")
|
2019-01-05 22:44:33 +00:00
|
|
|
|
2019-01-08 10:29:09 +00:00
|
|
|
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")
|
2019-01-05 22:44:33 +00:00
|
|
|
|
2019-01-08 10:29:09 +00:00
|
|
|
api.Handle("/settings", monkey(settingsGetHandler, "")).Methods("GET")
|
|
|
|
api.Handle("/settings", monkey(settingsPutHandler, "")).Methods("PUT")
|
2019-01-05 22:44:33 +00:00
|
|
|
|
2019-01-08 10:29:09 +00:00
|
|
|
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")
|
2019-01-05 23:01:16 +00:00
|
|
|
|
2019-01-05 22:44:33 +00:00
|
|
|
public := api.PathPrefix("/public").Subrouter()
|
2019-01-08 10:29:09 +00:00
|
|
|
public.PathPrefix("/dl").Handler(monkey(publicDlHandler, "/api/public/dl/")).Methods("GET")
|
|
|
|
public.PathPrefix("/share").Handler(monkey(publicShareHandler, "/api/public/share/")).Methods("GET")
|
2019-01-05 22:44:33 +00:00
|
|
|
|
|
|
|
return r, nil
|
|
|
|
}
|