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.OnInitialize(initConfig)
cobra.MousetrapHelpText = "" cobra.MousetrapHelpText = ""
rootCmd.SetVersionTemplate("File Browser version {{printf \"%s\" .Version}}\n") rootCmd.SetVersionTemplate("File Browser version {{printf \"%s\" .Version}}\n")
settings.Initialize()
log.Println(settings.GlobalConfiguration)
flags := rootCmd.Flags() flags := rootCmd.Flags()
persistent := rootCmd.PersistentFlags() 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".`, user created with the credentials from options "username" and "password".`,
Run: python(func(cmd *cobra.Command, args []string, d pythonData) { Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
serverConfig := settings.GlobalConfiguration.Server serverConfig := settings.GlobalConfiguration.Server
if !d.hadDB { if !d.hadDB {
quickSetup(cmd.Flags(), d) quickSetup(cmd.Flags(), d)
} }
workersCount := serverConfig.NumImageProcessors workersCount := serverConfig.NumImageProcessors
log.Println(serverConfig)
if workersCount < 1 { if workersCount < 1 {
log.Fatal("Image resize workers count could not be < 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 { func python(fn pythonFunc, cfg pythonConfig) cobraFunc {
return func(cmd *cobra.Command, args []string) { return func(cmd *cobra.Command, args []string) {
data := pythonData{hadDB: true} data := pythonData{hadDB: true}
path := settings.GlobalConfiguration.Server.Database
path := getParam(cmd.Flags(), "database")
exists, err := dbExists(path) exists, err := dbExists(path)
if err != nil { if err != nil {
@ -99,7 +100,6 @@ func python(fn pythonFunc, cfg pythonConfig) cobraFunc {
data.hadDB = exists data.hadDB = exists
db, err := storm.Open(path) db, err := storm.Open(path)
checkErr(err) checkErr(err)
defer db.Close() defer db.Close()
data.store, err = bolt.NewStorage(db) data.store, err = bolt.NewStorage(db)
checkErr(err) checkErr(err)

View File

@ -10,7 +10,7 @@ import (
var GlobalConfiguration Settings var GlobalConfiguration Settings
func Initialize() { func init() {
// Open and read the YAML file // Open and read the YAML file
yamlFile, err := os.Open("filebrowser.yml") yamlFile, err := os.Open("filebrowser.yml")
if err != nil { if err != nil {
@ -35,16 +35,17 @@ func Initialize() {
func setDefaults() { func setDefaults() {
GlobalConfiguration = Settings{ GlobalConfiguration = Settings{
Signup: true, Signup: true,
Server: Server{ Server: Server{
IndexingInterval: 5, IndexingInterval: 5,
Port: 8080, Port: 8080,
NumImageProcessors: 1, NumImageProcessors: 1,
BaseURL: "/files", BaseURL: "/files",
}, },
Auth: Auth{ Auth: Auth{
Method: "password",
Recaptcha: Recaptcha{ Recaptcha: Recaptcha{
Host: "", Host: "",
}, },
}, },
} }
} }

View File

@ -29,7 +29,7 @@ type Settings struct {
Shell []string `json:"shell"` Shell []string `json:"shell"`
Rules []rules.Rule `json:"rules"` Rules []rules.Rule `json:"rules"`
Server Server `json:"server"` Server Server `json:"server"`
Auth Auth `json:"auth"` Auth Auth `json:"auth"`
Frontend Frontend `json:"frontend"` Frontend Frontend `json:"frontend"`
@ -38,22 +38,22 @@ type Settings struct {
type Auth struct { type Auth struct {
Recaptcha Recaptcha Recaptcha Recaptcha
Header string `json:"header"` Header string `json:"header"`
Method string `json:"method"` Method string `json:"method"`
Command string `json:"command"` Command string `json:"command"`
Signup bool `json:"signup"` Signup bool `json:"signup"`
Shell string `json:"shell"` Shell string `json:"shell"`
} }
type Recaptcha struct { type Recaptcha struct {
Host string Host string
Key string Key string
Secret string Secret string
} }
type Server struct { type Server struct {
IndexingInterval uint32 IndexingInterval uint32 `json:"indexingInterval"`
NumImageProcessors int NumImageProcessors int `json:"numImageProcessors"`
Socket string `json:"socket"` Socket string `json:"socket"`
TLSKey string `json:"tlsKey"` TLSKey string `json:"tlsKey"`
TLSCert string `json:"tlsCert"` TLSCert string `json:"tlsCert"`
@ -62,7 +62,7 @@ type Server struct {
EnableExec bool `json:"enableExec"` EnableExec bool `json:"enableExec"`
TypeDetectionByHeader bool `json:"typeDetectionByHeader"` TypeDetectionByHeader bool `json:"typeDetectionByHeader"`
AuthHook string `json:"authHook"` AuthHook string `json:"authHook"`
Port int `json:"port"` Port int `json:"port"`
BaseURL string `json:"baseURL"` BaseURL string `json:"baseURL"`
Address string `json:"address"` Address string `json:"address"`
Log string `json:"log"` Log string `json:"log"`