Skip to content

Commit

Permalink
feat: web config add stroage dir item (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie authored Mar 29, 2024
1 parent 1d3a028 commit bd6d6be
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
15 changes: 10 additions & 5 deletions cmd/web/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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()

Expand All @@ -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
}

Expand Down
13 changes: 9 additions & 4 deletions cmd/web/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit bd6d6be

Please sign in to comment.