diff --git a/cmd/docs.go b/cmd/docs.go index 2e199b29..34aee2b3 100644 --- a/cmd/docs.go +++ b/cmd/docs.go @@ -111,7 +111,7 @@ func generateMarkdown(cmd *cobra.Command, w io.Writer) { checkErr(err) } -func generateFlagsTable(fs *pflag.FlagSet, buf *bytes.Buffer) { +func generateFlagsTable(fs *pflag.FlagSet, buf io.StringWriter) { buf.WriteString("| Name | Shorthand | Usage |\n") buf.WriteString("|------|-----------|-------|\n") diff --git a/cmd/root.go b/cmd/root.go index 0e8ddaca..016e8128 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -213,8 +213,8 @@ func setupLog(logMethod string) { func quickSetup(flags *pflag.FlagSet, d pythonData) { set := &settings.Settings{ - Key: generateKey(), - Signup: false, + Key: generateKey(), + Signup: false, CreateUserDir: false, Defaults: settings.UserDefaults{ Scope: ".", diff --git a/cmd/users_add.go b/cmd/users_add.go index 73c71091..b5ccd252 100644 --- a/cmd/users_add.go +++ b/cmd/users_add.go @@ -1,7 +1,6 @@ package cmd import ( - "github.com/filebrowser/filebrowser/v2/settings" "github.com/filebrowser/filebrowser/v2/users" "github.com/spf13/cobra" ) @@ -40,7 +39,7 @@ var usersAddCmd = &cobra.Command{ s2, err := d.store.Settings.Get() checkErr(err) - userHome, err := settings.CreateUserDir(user.Username, user.Scope, servSettings.Root, s2) + userHome, err := s2.MakeUserDir(user.Username, user.Scope, servSettings.Root) checkErr(err) user.Scope = userHome diff --git a/http/settings.go b/http/settings.go index 58036f71..0148b383 100644 --- a/http/settings.go +++ b/http/settings.go @@ -9,24 +9,24 @@ import ( ) 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"` + 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, + 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, + 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) diff --git a/http/users.go b/http/users.go index 75557235..b6a92dc3 100644 --- a/http/users.go +++ b/http/users.go @@ -2,7 +2,6 @@ package http import ( "encoding/json" - "github.com/filebrowser/filebrowser/v2/settings" "log" "net/http" "sort" @@ -121,7 +120,7 @@ var userPostHandler = withAdmin(func(w http.ResponseWriter, r *http.Request, d * return http.StatusInternalServerError, err } - userHome,err := settings.CreateUserDir(req.Data.Username, req.Data.Scope, d.server.Root, d.settings) + userHome, err := d.settings.MakeUserDir(req.Data.Username, req.Data.Scope, d.server.Root) if err != nil { log.Printf("create user: failed to mkdir user home dir: [%s]", userHome) return http.StatusInternalServerError, err diff --git a/settings/dir.go b/settings/dir.go index f66bbd81..bd21d8cc 100644 --- a/settings/dir.go +++ b/settings/dir.go @@ -2,11 +2,12 @@ package settings import ( "errors" - "github.com/spf13/afero" "log" "os" "regexp" "strings" + + "github.com/spf13/afero" ) var ( @@ -15,10 +16,11 @@ var ( dashes = regexp.MustCompile(`[\-]+`) ) -func CreateUserDir(username, userScope, serverRoot string, settings *Settings) (string, error) { +// MakeUserDir makes the user directory according to settings. +func (settings *Settings) MakeUserDir(username, userScope, serverRoot string) (string, error) { var err error userScope = strings.TrimSpace(userScope) - if userScope == "" || userScope == "./" { + if userScope == "" || userScope == "./" { userScope = "." } @@ -56,10 +58,9 @@ func CreateUserDir(username, userScope, serverRoot string, settings *Settings) ( } else { log.Printf("create user: mkdir user home dir: [%s] successfully.", userHome) } - return userHome,err + return userHome, err } - func cleanUsername(s string) string { // Remove any trailing space to avoid ending on - @@ -74,4 +75,4 @@ func cleanUsername(s string) string { s = dashes.ReplaceAllString(s, "-") return s -} \ No newline at end of file +} diff --git a/settings/settings.go b/settings/settings.go index 92713cb9..c94c2452 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -12,15 +12,15 @@ type AuthMethod string // Settings contain the main settings of the application. type Settings struct { - Key []byte `json:"key"` - Signup bool `json:"signup"` - CreateUserDir bool `json:"createUserDir"` - Defaults UserDefaults `json:"defaults"` - AuthMethod AuthMethod `json:"authMethod"` - Branding Branding `json:"branding"` - Commands map[string][]string `json:"commands"` - Shell []string `json:"shell"` - Rules []rules.Rule `json:"rules"` + Key []byte `json:"key"` + Signup bool `json:"signup"` + CreateUserDir bool `json:"createUserDir"` + Defaults UserDefaults `json:"defaults"` + AuthMethod AuthMethod `json:"authMethod"` + Branding Branding `json:"branding"` + Commands map[string][]string `json:"commands"` + Shell []string `json:"shell"` + Rules []rules.Rule `json:"rules"` } // GetRules implements rules.Provider.