You've already forked filebrowser
mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-11-26 14:25:26 +08:00
feat: wrap commands to send info (#612)
Wrap commands in a better way to pass storage
Former-commit-id: 9a3790c193936b53fe3826d1e051795efd30670b [formerly 04a9f34933a162cf4a98bc1e019f0d6c6404aae7] [formerly ab9be7f27b55a94e6a0f053df6908e357d4b396c [formerly 01ff03e426]]
Former-commit-id: ae7b61281dec2b5527f6032dc6f8c1bd8bb51296 [formerly 780ccc3b166e72bf53114bbfc0a95c0b7ffd8656]
Former-commit-id: 68ee8f7f3931f8e571b0188c96951077d6529cd7
This commit is contained in:
@@ -1,15 +1,11 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/asdine/storm"
|
||||
"github.com/filebrowser/filebrowser/v2/settings"
|
||||
"github.com/spf13/cobra"
|
||||
v "github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -26,20 +22,11 @@ this options can be changed in the future with the command
|
||||
to the defaults when creating new users and you don't
|
||||
override the options.`,
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
databasePath := v.GetString("database")
|
||||
if _, err := os.Stat(databasePath); err == nil {
|
||||
panic(errors.New(databasePath + " already exists"))
|
||||
}
|
||||
|
||||
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
||||
defaults := settings.UserDefaults{}
|
||||
getUserDefaults(cmd, &defaults, true)
|
||||
authMethod, auther := getAuthentication(cmd)
|
||||
|
||||
db, err := storm.Open(databasePath)
|
||||
checkErr(err)
|
||||
defer db.Close()
|
||||
st := getStorage(db)
|
||||
s := &settings.Settings{
|
||||
Key: generateRandomBytes(64), // 256 bit
|
||||
Signup: mustGetBool(cmd, "signup"),
|
||||
@@ -53,9 +40,9 @@ override the options.`,
|
||||
},
|
||||
}
|
||||
|
||||
err = st.Settings.Save(s)
|
||||
err := d.store.Settings.Save(s)
|
||||
checkErr(err)
|
||||
err = st.Auth.Save(auther)
|
||||
err = d.store.Auth.Save(auther)
|
||||
checkErr(err)
|
||||
|
||||
fmt.Printf(`
|
||||
@@ -64,5 +51,5 @@ Now add your first user via 'filebrowser users new' and then you just
|
||||
need to call the main command to boot up the server.
|
||||
`)
|
||||
printSettings(s, auther)
|
||||
},
|
||||
}, pythonConfig{noDB: true}),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user