MCPcopy
hub / github.com/filebrowser/filebrowser / NewHandler

Function NewHandler

http/http.go:19–94  ·  view source on GitHub ↗
(
	imgSvc ImgService,
	fileCache FileCache,
	uploadCache UploadCache,
	store *storage.Storage,
	server *settings.Server,
	assetsFs fs.FS,
)

Source from the content-addressed store, hash-verified

17}
18
19func NewHandler(
20 imgSvc ImgService,
21 fileCache FileCache,
22 uploadCache UploadCache,
23 store *storage.Storage,
24 server *settings.Server,
25 assetsFs fs.FS,
26) (http.Handler, error) {
27 server.Clean()
28
29 r := mux.NewRouter()
30 r.Use(func(next http.Handler) http.Handler {
31 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
32 w.Header().Set("Content-Security-Policy", `default-src 'self'; style-src 'unsafe-inline';`)
33 next.ServeHTTP(w, r)
34 })
35 })
36 index, static := getStaticHandlers(store, server, assetsFs)
37
38 monkey := func(fn handleFunc, prefix string) http.Handler {
39 return handle(fn, prefix, store, server)
40 }
41
42 r.HandleFunc("/health", healthHandler)
43 r.PathPrefix("/static").Handler(static)
44 r.NotFoundHandler = index
45
46 api := r.PathPrefix("/api").Subrouter()
47
48 tokenExpirationTime := server.GetTokenExpirationTime(DefaultTokenExpirationTime)
49 api.Handle("/login", monkey(loginHandler(tokenExpirationTime), ""))
50 api.Handle("/signup", monkey(signupHandler, ""))
51 api.Handle("/renew", monkey(renewHandler(tokenExpirationTime), ""))
52
53 users := api.PathPrefix("/users").Subrouter()
54 users.Handle("", monkey(usersGetHandler, "")).Methods("GET")
55 users.Handle("", monkey(userPostHandler, "")).Methods("POST")
56 users.Handle("/{id:[0-9]+}", monkey(userPutHandler, "")).Methods("PUT")
57 users.Handle("/{id:[0-9]+}", monkey(userGetHandler, "")).Methods("GET")
58 users.Handle("/{id:[0-9]+}", monkey(userDeleteHandler, "")).Methods("DELETE")
59
60 api.PathPrefix("/resources/recursive").Handler(monkey(resourceGetRecursiveHandler, "/api/resources/recursive")).Methods("GET")
61 api.PathPrefix("/resources").Handler(monkey(resourceGetHandler, "/api/resources")).Methods("GET")
62 api.PathPrefix("/resources").Handler(monkey(resourceDeleteHandler(fileCache), "/api/resources")).Methods("DELETE")
63 api.PathPrefix("/resources").Handler(monkey(resourcePostHandler(fileCache), "/api/resources")).Methods("POST")
64 api.PathPrefix("/resources").Handler(monkey(resourcePutHandler, "/api/resources")).Methods("PUT")
65 api.PathPrefix("/resources").Handler(monkey(resourcePatchHandler(fileCache), "/api/resources")).Methods("PATCH")
66
67 api.PathPrefix("/tus").Handler(monkey(tusPostHandler(uploadCache), "/api/tus")).Methods("POST")
68 api.PathPrefix("/tus").Handler(monkey(tusHeadHandler(uploadCache), "/api/tus")).Methods("HEAD", "GET")
69 api.PathPrefix("/tus").Handler(monkey(tusPatchHandler(uploadCache), "/api/tus")).Methods("PATCH")
70 api.PathPrefix("/tus").Handler(monkey(tusDeleteHandler(uploadCache), "/api/tus")).Methods("DELETE")
71
72 api.PathPrefix("/usage").Handler(monkey(diskUsage, "/api/usage")).Methods("GET")
73
74 api.Handle("/shares", monkey(shareListHandler, "")).Methods("GET")
75 api.PathPrefix("/share").Handler(monkey(shareGetsHandler, "/api/share")).Methods("GET")
76 api.PathPrefix("/share").Handler(monkey(sharePostHandler, "/api/share")).Methods("POST")

Callers

nothing calls this directly

Calls 15

getStaticHandlersFunction · 0.85
handleFunction · 0.85
loginHandlerFunction · 0.85
renewHandlerFunction · 0.85
resourceDeleteHandlerFunction · 0.85
resourcePostHandlerFunction · 0.85
resourcePatchHandlerFunction · 0.85
tusPostHandlerFunction · 0.85
tusHeadHandlerFunction · 0.85
tusPatchHandlerFunction · 0.85
tusDeleteHandlerFunction · 0.85
previewHandlerFunction · 0.85

Tested by

no test coverage detected