diff --git a/main.go b/main.go index 0feadaa..7726081 100644 --- a/main.go +++ b/main.go @@ -12,9 +12,9 @@ import ( var ( port int + configFile string downloadPath string downloaderPath string - configFile string //go:embed frontend/dist frontend embed.FS @@ -22,9 +22,9 @@ var ( func init() { flag.IntVar(&port, "port", 3033, "Port where server will listen at") + flag.StringVar(&configFile, "conf", "", "yt-dlp-WebUI config file path") flag.StringVar(&downloadPath, "out", ".", "Directory where files will be saved") flag.StringVar(&downloaderPath, "driver", "yt-dlp", "yt-dlp executable path") - flag.StringVar(&configFile, "conf", "", "yt-dlp-WebUI config file path") flag.Parse() } @@ -35,15 +35,15 @@ func main() { log.Fatalln(err) } - cfg := config.Instance() + c := config.Instance() + + c.SetPort(port) + c.DownloadPath(downloadPath) + c.DownloaderPath(downloaderPath) if configFile != "" { - cfg.LoadFromFile(configFile) + c.LoadFromFile(configFile) } - cfg.SetPort(port) - cfg.DownloadPath(downloadPath) - cfg.DownloaderPath(downloaderPath) - server.RunBlocking(port, frontend) } diff --git a/server/config/parser.go b/server/config/parser.go index fae1c04..38dfe69 100644 --- a/server/config/parser.go +++ b/server/config/parser.go @@ -7,7 +7,7 @@ import ( "gopkg.in/yaml.v3" ) -var lock = &sync.Mutex{} +var lock sync.Mutex type serverConfig struct { Port int `yaml:"port"` diff --git a/server/server.go b/server/server.go index 29737f1..0b49819 100644 --- a/server/server.go +++ b/server/server.go @@ -81,8 +81,8 @@ func RunBlocking(port int, frontend fs.FS) { app.Server().StreamRequestBody = true - go periodicallyPersist() go gracefulShutdown(app) + go autoPersist(time.Minute * 5) log.Fatal(app.Listen(fmt.Sprintf(":%d", port))) } @@ -106,9 +106,9 @@ func gracefulShutdown(app *fiber.App) { }() } -func periodicallyPersist() { +func autoPersist(d time.Duration) { for { db.Persist() - time.Sleep(time.Minute * 5) + time.Sleep(d) } }