it just works
This commit is contained in:
31
main.go
31
main.go
@@ -3,34 +3,51 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"embed"
|
||||
"flag"
|
||||
"io/fs"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/marcopeocchi/yt-dlp-web-ui/server"
|
||||
"github.com/marcopeocchi/yt-dlp-web-ui/server/config"
|
||||
)
|
||||
|
||||
type ContextKey interface{}
|
||||
|
||||
var (
|
||||
port = os.Getenv("PORT")
|
||||
//go:embed dist/frontend
|
||||
port int
|
||||
downloadPath string
|
||||
downloaderPath string
|
||||
configFile string
|
||||
|
||||
//go:embed frontend/dist
|
||||
frontend embed.FS
|
||||
)
|
||||
|
||||
func init() {
|
||||
if port == "" {
|
||||
port = "3033"
|
||||
}
|
||||
flag.IntVar(&port, "port", 3033, "Port where server will listen at")
|
||||
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()
|
||||
}
|
||||
|
||||
func main() {
|
||||
frontend, err := fs.Sub(frontend, "dist/frontend")
|
||||
frontend, err := fs.Sub(frontend, "frontend/dist")
|
||||
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
cfg := config.Instance()
|
||||
|
||||
if configFile != "" {
|
||||
cfg.LoadFromFile(configFile)
|
||||
}
|
||||
|
||||
cfg.SetPort(port)
|
||||
cfg.DownloadPath(downloadPath)
|
||||
cfg.DownloaderPath(downloaderPath)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, ContextKey("port"), port)
|
||||
ctx = context.WithValue(ctx, ContextKey("frontend"), frontend)
|
||||
|
||||
Reference in New Issue
Block a user