lint: lint the code
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
Former-commit-id: 984c56e0b9a9169b10c6017fbd68ab4fbd3868d7 [formerly 27c43314222c723a220b9b1d2141e1509ed05627] [formerly 0a9f6c47bff2d653035c93765ea08ade73ec450c [formerly b7fdcc3ee9
]]
Former-commit-id: c27e7fa41f20f433a9a0a97ecc40ab78968b43dc [formerly 185db4a17969cd4fb76cc2b06bd58221c9c6c100]
Former-commit-id: 9b26d1b0642c61cd38f7cdf422f95b2bf9a9614d
pull/726/head
parent
4a1e21baec
commit
fa86894550
|
@ -111,7 +111,7 @@ func generateMarkdown(cmd *cobra.Command, w io.Writer) {
|
||||||
checkErr(err)
|
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("| Name | Shorthand | Usage |\n")
|
||||||
buf.WriteString("|------|-----------|-------|\n")
|
buf.WriteString("|------|-----------|-------|\n")
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/filebrowser/filebrowser/v2/settings"
|
|
||||||
"github.com/filebrowser/filebrowser/v2/users"
|
"github.com/filebrowser/filebrowser/v2/users"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
@ -40,7 +39,7 @@ var usersAddCmd = &cobra.Command{
|
||||||
s2, err := d.store.Settings.Get()
|
s2, err := d.store.Settings.Get()
|
||||||
checkErr(err)
|
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)
|
checkErr(err)
|
||||||
user.Scope = userHome
|
user.Scope = userHome
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ package http
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/filebrowser/filebrowser/v2/settings"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -121,7 +120,7 @@ var userPostHandler = withAdmin(func(w http.ResponseWriter, r *http.Request, d *
|
||||||
return http.StatusInternalServerError, err
|
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 {
|
if err != nil {
|
||||||
log.Printf("create user: failed to mkdir user home dir: [%s]", userHome)
|
log.Printf("create user: failed to mkdir user home dir: [%s]", userHome)
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
|
|
|
@ -2,11 +2,12 @@ package settings
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/spf13/afero"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/afero"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -15,7 +16,8 @@ var (
|
||||||
dashes = regexp.MustCompile(`[\-]+`)
|
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
|
var err error
|
||||||
userScope = strings.TrimSpace(userScope)
|
userScope = strings.TrimSpace(userScope)
|
||||||
if userScope == "" || userScope == "./" {
|
if userScope == "" || userScope == "./" {
|
||||||
|
@ -59,7 +61,6 @@ func CreateUserDir(username, userScope, serverRoot string, settings *Settings) (
|
||||||
return userHome, err
|
return userHome, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func cleanUsername(s string) string {
|
func cleanUsername(s string) string {
|
||||||
|
|
||||||
// Remove any trailing space to avoid ending on -
|
// Remove any trailing space to avoid ending on -
|
||||||
|
|
Loading…
Reference in New Issue