This commit is contained in:
Graham Steffaniak 2023-09-01 19:51:13 -05:00
parent 1cd055d768
commit 91f4a299c4
4 changed files with 24 additions and 25 deletions

View File

@ -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")
}

View File

@ -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)

View File

@ -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: "",
},
},
}
}
}
}

View File

@ -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"`