feat: web config add stroage dir item (#428)

This commit is contained in:
Levi authored and GitHub committed 2024-03-29 17:10:25 +08:00
1 parent 1d3a028bae
commit bd6d6be71f
2 files changed
+19 -9

No files matched your search

+10 -5
View File
@@ -9,11 +9,12 @@ import (
) )
type args struct { type args struct {
Address *string `json:"address"` Address *string `json:"address"`
Port *int `json:"port"` Port *int `json:"port"`
Username *string `json:"username"` Username *string `json:"username"`
Password *string `json:"password"` Password *string `json:"password"`
ApiToken *string `json:"apiToken"` ApiToken *string `json:"apiToken"`
StorageDir *string `json:"storageDir"`
configPath *string configPath *string
} }
@@ -25,6 +26,7 @@ func parse() *args {
cliArgs.Username = flag.String("u", "gopeed", "HTTP Basic Auth Username") cliArgs.Username = flag.String("u", "gopeed", "HTTP Basic Auth Username")
cliArgs.Password = flag.String("p", "", "HTTP Basic Auth Pwd") cliArgs.Password = flag.String("p", "", "HTTP Basic Auth Pwd")
cliArgs.ApiToken = flag.String("T", "", "API token, that can only be used when basic authentication is enabled.") cliArgs.ApiToken = flag.String("T", "", "API token, that can only be used when basic authentication is enabled.")
cliArgs.StorageDir = flag.String("d", "", "Storage directory")
cliArgs.configPath = flag.String("c", "./config.json", "Config file path") cliArgs.configPath = flag.String("c", "./config.json", "Config file path")
flag.Parse() flag.Parse()
@@ -45,6 +47,9 @@ func parse() *args {
if cfgArgs.ApiToken == nil { if cfgArgs.ApiToken == nil {
cfgArgs.ApiToken = cliArgs.ApiToken cfgArgs.ApiToken = cliArgs.ApiToken
} }
if cfgArgs.StorageDir == nil {
cfgArgs.StorageDir = cliArgs.StorageDir
}
return cfgArgs return cfgArgs
} }
+9 -4
View File
@@ -31,11 +31,16 @@ func main() {
} }
} }
exe, err := os.Executable() var dir string
if err != nil { if args.StorageDir != nil && *args.StorageDir != "" {
panic(err) dir = *args.StorageDir
} else {
exe, err := os.Executable()
if err != nil {
panic(err)
}
dir = filepath.Dir(exe)
} }
dir := filepath.Dir(exe)
cfg := &model.StartConfig{ cfg := &model.StartConfig{
Network: "tcp", Network: "tcp",