diff --git a/backend/cmd/root.go b/backend/cmd/root.go index 27da4658..80de79c8 100644 --- a/backend/cmd/root.go +++ b/backend/cmd/root.go @@ -45,9 +45,7 @@ func init() { cobra.OnInitialize(initConfig) cobra.MousetrapHelpText = "" rootCmd.SetVersionTemplate("File Browser version {{printf \"%s\" .Version}}\n") - settings.Initialize() - log.Println(settings.GlobalConfiguration) flags := rootCmd.Flags() persistent := rootCmd.PersistentFlags() @@ -88,12 +86,12 @@ the quick setup mode and a new database will be bootstraped and a new user created with the credentials from options "username" and "password".`, Run: python(func(cmd *cobra.Command, args []string, d pythonData) { serverConfig := settings.GlobalConfiguration.Server - if !d.hadDB { quickSetup(cmd.Flags(), d) } workersCount := serverConfig.NumImageProcessors + log.Println(serverConfig) if workersCount < 1 { log.Fatal("Image resize workers count could not be < 1") } diff --git a/backend/cmd/utils.go b/backend/cmd/utils.go index 0ae50265..ef0b9a7c 100644 --- a/backend/cmd/utils.go +++ b/backend/cmd/utils.go @@ -85,7 +85,8 @@ func dbExists(path string) (bool, error) { func python(fn pythonFunc, cfg pythonConfig) cobraFunc { return func(cmd *cobra.Command, args []string) { data := pythonData{hadDB: true} - path := settings.GlobalConfiguration.Server.Database + + path := getParam(cmd.Flags(), "database") exists, err := dbExists(path) if err != nil { @@ -99,7 +100,6 @@ func python(fn pythonFunc, cfg pythonConfig) cobraFunc { data.hadDB = exists db, err := storm.Open(path) checkErr(err) - defer db.Close() data.store, err = bolt.NewStorage(db) checkErr(err) diff --git a/backend/settings/config.go b/backend/settings/config.go index 4f093c05..e3b41bdd 100644 --- a/backend/settings/config.go +++ b/backend/settings/config.go @@ -10,7 +10,7 @@ import ( var GlobalConfiguration Settings -func Initialize() { +func init() { // Open and read the YAML file yamlFile, err := os.Open("filebrowser.yml") if err != nil { @@ -35,16 +35,17 @@ func Initialize() { func setDefaults() { GlobalConfiguration = Settings{ Signup: true, - Server: Server{ - IndexingInterval: 5, - Port: 8080, + Server: Server{ + IndexingInterval: 5, + Port: 8080, NumImageProcessors: 1, - BaseURL: "/files", - }, + BaseURL: "/files", + }, Auth: Auth{ + Method: "password", Recaptcha: Recaptcha{ Host: "", }, }, - } -} \ No newline at end of file + } +} diff --git a/backend/settings/structs.go b/backend/settings/structs.go index a4317ba4..fba392e7 100644 --- a/backend/settings/structs.go +++ b/backend/settings/structs.go @@ -29,7 +29,7 @@ type Settings struct { Shell []string `json:"shell"` Rules []rules.Rule `json:"rules"` Server Server `json:"server"` - Auth Auth `json:"auth"` + Auth Auth `json:"auth"` Frontend Frontend `json:"frontend"` @@ -38,22 +38,22 @@ type Settings struct { type Auth struct { Recaptcha Recaptcha - Header string `json:"header"` - Method string `json:"method"` - Command string `json:"command"` - Signup bool `json:"signup"` - Shell string `json:"shell"` + Header string `json:"header"` + Method string `json:"method"` + Command string `json:"command"` + Signup bool `json:"signup"` + Shell string `json:"shell"` } type Recaptcha struct { - Host string - Key string - Secret string + Host string + Key string + Secret string } type Server struct { - IndexingInterval uint32 - NumImageProcessors int + IndexingInterval uint32 `json:"indexingInterval"` + NumImageProcessors int `json:"numImageProcessors"` Socket string `json:"socket"` TLSKey string `json:"tlsKey"` TLSCert string `json:"tlsCert"` @@ -62,7 +62,7 @@ type Server struct { EnableExec bool `json:"enableExec"` TypeDetectionByHeader bool `json:"typeDetectionByHeader"` AuthHook string `json:"authHook"` - Port int `json:"port"` + Port int `json:"port"` BaseURL string `json:"baseURL"` Address string `json:"address"` Log string `json:"log"`