From bd6d6be71f4b4363071f34a413fe25930cb00e6b Mon Sep 17 00:00:00 2001 From: Levi Date: Fri, 29 Mar 2024 17:10:25 +0800 Subject: [PATCH] feat: web config add stroage dir item (#428) --- cmd/web/flags.go | 15 ++++++++++----- cmd/web/main.go | 13 +++++++++---- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/cmd/web/flags.go b/cmd/web/flags.go index 326a9c4f4..36f74002b 100644 --- a/cmd/web/flags.go +++ b/cmd/web/flags.go @@ -9,11 +9,12 @@ import ( ) type args struct { - Address *string `json:"address"` - Port *int `json:"port"` - Username *string `json:"username"` - Password *string `json:"password"` - ApiToken *string `json:"apiToken"` + Address *string `json:"address"` + Port *int `json:"port"` + Username *string `json:"username"` + Password *string `json:"password"` + ApiToken *string `json:"apiToken"` + StorageDir *string `json:"storageDir"` configPath *string } @@ -25,6 +26,7 @@ func parse() *args { cliArgs.Username = flag.String("u", "gopeed", "HTTP Basic Auth Username") 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.StorageDir = flag.String("d", "", "Storage directory") cliArgs.configPath = flag.String("c", "./config.json", "Config file path") flag.Parse() @@ -45,6 +47,9 @@ func parse() *args { if cfgArgs.ApiToken == nil { cfgArgs.ApiToken = cliArgs.ApiToken } + if cfgArgs.StorageDir == nil { + cfgArgs.StorageDir = cliArgs.StorageDir + } return cfgArgs } diff --git a/cmd/web/main.go b/cmd/web/main.go index e304c1cc0..76a15d035 100644 --- a/cmd/web/main.go +++ b/cmd/web/main.go @@ -31,11 +31,16 @@ func main() { } } - exe, err := os.Executable() - if err != nil { - panic(err) + var dir string + if args.StorageDir != nil && *args.StorageDir != "" { + dir = *args.StorageDir + } else { + exe, err := os.Executable() + if err != nil { + panic(err) + } + dir = filepath.Dir(exe) } - dir := filepath.Dir(exe) cfg := &model.StartConfig{ Network: "tcp",