code refactoring

This commit is contained in:
2023-05-31 10:21:30 +02:00
parent cfd6b78695
commit 78c1559e84
3 changed files with 12 additions and 12 deletions

16
main.go
View File

@@ -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)
}

View File

@@ -7,7 +7,7 @@ import (
"gopkg.in/yaml.v3"
)
var lock = &sync.Mutex{}
var lock sync.Mutex
type serverConfig struct {
Port int `yaml:"port"`

View File

@@ -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)
}
}