mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-04 08:10:55 +00:00
Replace server startup panics with returned errors, print actionable CLI messages with exit status 1, and clarify the API token flags. Add regressions for missing web authentication credentials. Fixes GopeedLab/gopeed#1614
74 lines
1.5 KiB
Go
74 lines
1.5 KiB
Go
//go:build web
|
|
// +build web
|
|
|
|
package main
|
|
|
|
import (
|
|
"embed"
|
|
"fmt"
|
|
"io/fs"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/GopeedLab/gopeed/cmd"
|
|
"github.com/GopeedLab/gopeed/pkg/rest/model"
|
|
)
|
|
|
|
//go:embed dist/*
|
|
var dist embed.FS
|
|
|
|
func main() {
|
|
sub, err := fs.Sub(dist, "dist")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
args := parse()
|
|
var webAuth *model.WebAuth
|
|
if isNotBlank(args.Username) && isNotBlank(args.Password) {
|
|
webAuth = &model.WebAuth{
|
|
Username: *args.Username,
|
|
Password: *args.Password,
|
|
}
|
|
}
|
|
|
|
var storageDir string
|
|
if args.StorageDir != nil && *args.StorageDir != "" {
|
|
storageDir = *args.StorageDir
|
|
} else {
|
|
exe, err := os.Executable()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
storageDir = filepath.Join(filepath.Dir(exe), "storage")
|
|
}
|
|
|
|
tempDir := ""
|
|
if args.TempDir != nil {
|
|
tempDir = *args.TempDir
|
|
}
|
|
cfg := &model.StartConfig{
|
|
Network: "tcp",
|
|
Address: fmt.Sprintf("%s:%d", *args.Address, *args.Port),
|
|
Storage: model.StorageBolt,
|
|
StorageDir: storageDir,
|
|
TempDir: tempDir,
|
|
WhiteDownloadDirs: args.WhiteDownloadDirs,
|
|
ApiToken: *args.ApiToken,
|
|
MCPEnable: args.MCPEnable,
|
|
DownloadConfig: args.DownloadConfig,
|
|
ProductionMode: true,
|
|
WebEnable: true,
|
|
WebFS: sub,
|
|
WebAuth: webAuth,
|
|
}
|
|
if err := cmd.Start(cfg); err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func isNotBlank(str *string) bool {
|
|
return str != nil && *str != ""
|
|
}
|