MCPcopy Create free account
hub / github.com/filebrowser/filebrowser / handleWithStaticData

Function handleWithStaticData

http/static.go:24–104  ·  view source on GitHub ↗
(w http.ResponseWriter, _ *http.Request, d *data, fSys fs.FS, file, contentType string)

Source from the content-addressed store, hash-verified

22)
23
24func handleWithStaticData(w http.ResponseWriter, _ *http.Request, d *data, fSys fs.FS, file, contentType string) (int, error) {
25 w.Header().Set("Content-Type", contentType)
26
27 auther, err := d.store.Auth.Get(d.settings.AuthMethod)
28 if err != nil {
29 return http.StatusInternalServerError, err
30 }
31
32 data := map[string]interface{}{
33 "Name": d.settings.Branding.Name,
34 "DisableExternal": d.settings.Branding.DisableExternal,
35 "DisableUsedPercentage": d.settings.Branding.DisableUsedPercentage,
36 "Color": d.settings.Branding.Color,
37 "BaseURL": d.server.BaseURL,
38 "Version": version.Version,
39 "StaticURL": path.Join(d.server.BaseURL, "/static"),
40 "Signup": d.settings.Signup,
41 "NoAuth": d.settings.AuthMethod == auth.MethodNoAuth,
42 "AuthMethod": d.settings.AuthMethod,
43 "LogoutPage": d.settings.LogoutPage,
44 "LoginPage": auther.LoginPage(),
45 "CSS": false,
46 "ReCaptcha": false,
47 "Theme": d.settings.Branding.Theme,
48 "EnableThumbs": d.server.EnableThumbnails,
49 "ResizePreview": d.server.ResizePreview,
50 "EnableExec": d.server.EnableExec,
51 "TusSettings": d.settings.Tus,
52 "HideLoginButton": d.settings.HideLoginButton,
53 }
54
55 if d.settings.Branding.Files != "" {
56 fPath := filepath.Join(d.settings.Branding.Files, "custom.css")
57 _, err := os.Stat(fPath)
58
59 if err != nil && !os.IsNotExist(err) {
60 log.Printf("couldn't load custom styles: %v", err)
61 }
62
63 if err == nil {
64 data["CSS"] = true
65 }
66 }
67
68 if d.settings.AuthMethod == auth.MethodJSONAuth {
69 raw, err := d.store.Auth.Get(d.settings.AuthMethod)
70 if err != nil {
71 return http.StatusInternalServerError, err
72 }
73
74 auther := raw.(*auth.JSONAuth)
75
76 if auther.ReCaptcha != nil {
77 data["ReCaptcha"] = auther.ReCaptcha.Key != "" && auther.ReCaptcha.Secret != ""
78 data["ReCaptchaHost"] = auther.ReCaptcha.Host
79 data["ReCaptchaKey"] = auther.ReCaptcha.Key
80 }
81 }

Callers 1

getStaticHandlersFunction · 0.85

Calls 3

GetMethod · 0.65
LoginPageMethod · 0.65
StatMethod · 0.45

Tested by

no test coverage detected