filebrowser/http/settings.go
荒野無燈 65a53514d5 global settings: add createUserDir option. new feature: auto create user home dir while adding user.
Former-commit-id: 331a76abdc611236ccc761d0fd9a814ed1ee0c35 [formerly 0c1024a5b8109c84d213e0cbdbe05e10eb5793d4] [formerly 467e1789f55c410ff2ca9e9ef125d9fe28410bc9 [formerly e8570e4dba]]
Former-commit-id: 1eed58870b6e009d84806db6b55efc5fc3983e2a [formerly 3e9083f7758e72bd307ed23c4b512a8ab5adc523]
Former-commit-id: 5023ef77eb92636e62fde511ea609114e667a7d7
2019-02-19 11:55:18 +08:00

53 lines
1.4 KiB
Go

package http
import (
"encoding/json"
"net/http"
"github.com/filebrowser/filebrowser/v2/rules"
"github.com/filebrowser/filebrowser/v2/settings"
)
type settingsData struct {
Signup bool `json:"signup"`
CreateUserDir bool `json:"createUserDir"`
Defaults settings.UserDefaults `json:"defaults"`
Rules []rules.Rule `json:"rules"`
Branding settings.Branding `json:"branding"`
Shell []string `json:"shell"`
Commands map[string][]string `json:"commands"`
}
var settingsGetHandler = withAdmin(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
data := &settingsData{
Signup: d.settings.Signup,
CreateUserDir: d.settings.CreateUserDir,
Defaults: d.settings.Defaults,
Rules: d.settings.Rules,
Branding: d.settings.Branding,
Shell: d.settings.Shell,
Commands: d.settings.Commands,
}
return renderJSON(w, r, data)
})
var settingsPutHandler = withAdmin(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
req := &settingsData{}
err := json.NewDecoder(r.Body).Decode(req)
if err != nil {
return http.StatusBadRequest, err
}
d.settings.Signup = req.Signup
d.settings.CreateUserDir = req.CreateUserDir
d.settings.Defaults = req.Defaults
d.settings.Rules = req.Rules
d.settings.Branding = req.Branding
d.settings.Shell = req.Shell
d.settings.Commands = req.Commands
err = d.store.Settings.Save(d.settings)
return errToStatus(err), err
})