2019-01-05 22:44:33 +00:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/filebrowser/filebrowser/v2/rules"
|
|
|
|
"github.com/filebrowser/filebrowser/v2/settings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type settingsData struct {
|
2022-06-03 13:59:36 +00:00
|
|
|
Signup bool `json:"signup"`
|
|
|
|
CreateUserDir bool `json:"createUserDir"`
|
|
|
|
UserHomeBasePath string `json:"userHomeBasePath"`
|
|
|
|
Defaults settings.UserDefaults `json:"defaults"`
|
|
|
|
Rules []rules.Rule `json:"rules"`
|
|
|
|
Branding settings.Branding `json:"branding"`
|
2023-07-28 16:15:44 +00:00
|
|
|
Tus settings.Tus `json:"tus"`
|
2022-06-03 13:59:36 +00:00
|
|
|
Shell []string `json:"shell"`
|
|
|
|
Commands map[string][]string `json:"commands"`
|
2019-01-05 22:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var settingsGetHandler = withAdmin(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
|
|
|
|
data := &settingsData{
|
2022-06-03 13:59:36 +00:00
|
|
|
Signup: d.settings.Signup,
|
|
|
|
CreateUserDir: d.settings.CreateUserDir,
|
|
|
|
UserHomeBasePath: d.settings.UserHomeBasePath,
|
|
|
|
Defaults: d.settings.Defaults,
|
|
|
|
Rules: d.settings.Rules,
|
|
|
|
Branding: d.settings.Branding,
|
2023-07-28 16:15:44 +00:00
|
|
|
Tus: d.settings.Tus,
|
2022-06-03 13:59:36 +00:00
|
|
|
Shell: d.settings.Shell,
|
|
|
|
Commands: d.settings.Commands,
|
2019-01-05 22:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return renderJSON(w, r, data)
|
|
|
|
})
|
|
|
|
|
2024-04-01 16:24:06 +00:00
|
|
|
var settingsPutHandler = withAdmin(func(_ http.ResponseWriter, r *http.Request, d *data) (int, error) {
|
2019-01-05 22:44:33 +00:00
|
|
|
req := &settingsData{}
|
|
|
|
err := json.NewDecoder(r.Body).Decode(req)
|
|
|
|
if err != nil {
|
|
|
|
return http.StatusBadRequest, err
|
|
|
|
}
|
|
|
|
|
|
|
|
d.settings.Signup = req.Signup
|
2019-02-15 15:12:02 +00:00
|
|
|
d.settings.CreateUserDir = req.CreateUserDir
|
2022-06-03 13:59:36 +00:00
|
|
|
d.settings.UserHomeBasePath = req.UserHomeBasePath
|
2019-01-05 22:44:33 +00:00
|
|
|
d.settings.Defaults = req.Defaults
|
|
|
|
d.settings.Rules = req.Rules
|
|
|
|
d.settings.Branding = req.Branding
|
2023-07-28 16:15:44 +00:00
|
|
|
d.settings.Tus = req.Tus
|
2019-01-05 22:44:33 +00:00
|
|
|
d.settings.Shell = req.Shell
|
|
|
|
d.settings.Commands = req.Commands
|
|
|
|
|
|
|
|
err = d.store.Settings.Save(d.settings)
|
|
|
|
return errToStatus(err), err
|
|
|
|
})
|