code refactoring
This commit is contained in:
16
main.go
16
main.go
@@ -12,9 +12,9 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
port int
|
port int
|
||||||
|
configFile string
|
||||||
downloadPath string
|
downloadPath string
|
||||||
downloaderPath string
|
downloaderPath string
|
||||||
configFile string
|
|
||||||
|
|
||||||
//go:embed frontend/dist
|
//go:embed frontend/dist
|
||||||
frontend embed.FS
|
frontend embed.FS
|
||||||
@@ -22,9 +22,9 @@ var (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.IntVar(&port, "port", 3033, "Port where server will listen at")
|
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(&downloadPath, "out", ".", "Directory where files will be saved")
|
||||||
flag.StringVar(&downloaderPath, "driver", "yt-dlp", "yt-dlp executable path")
|
flag.StringVar(&downloaderPath, "driver", "yt-dlp", "yt-dlp executable path")
|
||||||
flag.StringVar(&configFile, "conf", "", "yt-dlp-WebUI config file path")
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,15 +35,15 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg := config.Instance()
|
c := config.Instance()
|
||||||
|
|
||||||
|
c.SetPort(port)
|
||||||
|
c.DownloadPath(downloadPath)
|
||||||
|
c.DownloaderPath(downloaderPath)
|
||||||
|
|
||||||
if configFile != "" {
|
if configFile != "" {
|
||||||
cfg.LoadFromFile(configFile)
|
c.LoadFromFile(configFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.SetPort(port)
|
|
||||||
cfg.DownloadPath(downloadPath)
|
|
||||||
cfg.DownloaderPath(downloaderPath)
|
|
||||||
|
|
||||||
server.RunBlocking(port, frontend)
|
server.RunBlocking(port, frontend)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var lock = &sync.Mutex{}
|
var lock sync.Mutex
|
||||||
|
|
||||||
type serverConfig struct {
|
type serverConfig struct {
|
||||||
Port int `yaml:"port"`
|
Port int `yaml:"port"`
|
||||||
|
|||||||
@@ -81,8 +81,8 @@ func RunBlocking(port int, frontend fs.FS) {
|
|||||||
|
|
||||||
app.Server().StreamRequestBody = true
|
app.Server().StreamRequestBody = true
|
||||||
|
|
||||||
go periodicallyPersist()
|
|
||||||
go gracefulShutdown(app)
|
go gracefulShutdown(app)
|
||||||
|
go autoPersist(time.Minute * 5)
|
||||||
|
|
||||||
log.Fatal(app.Listen(fmt.Sprintf(":%d", port)))
|
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 {
|
for {
|
||||||
db.Persist()
|
db.Persist()
|
||||||
time.Sleep(time.Minute * 5)
|
time.Sleep(d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user