From 4710db25ee0e1941700acdd83ce18e8e494196d2 Mon Sep 17 00:00:00 2001 From: Marco <35533749+marcopeocchi@users.noreply.github.com> Date: Tue, 26 Sep 2023 10:25:14 +0200 Subject: [PATCH] 82 session file location (#91) * change session file location * makefile refactor * gha refactor --- .github/workflows/docker-publish.yml | 4 ++-- Makefile | 7 +++---- main.go | 12 +++++++----- server/config/parser.go | 19 ++++++++++++------- server/internal/memory_db.go | 9 ++++++++- 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 0f136f8..cb467bc 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -76,5 +76,5 @@ jobs: # This step uses the identity token to provision an ephemeral certificate # against the sigstore community Fulcio instance. run: | - cosign sign ghcr.io/${{ github.repository }}@${{ steps.build-and-push.outputs.digest }} - cosign sign docker.io/${{ secrets.DOCKER_HUB_USERNAME }}/yt-dlp-webui@${{ steps.build-and-push.outputs.digest }} + cosign sign ghcr.io/${{ github.repository }}:latest + cosign sign docker.io/${{ secrets.DOCKER_HUB_USERNAME }}/yt-dlp-webui:latest diff --git a/Makefile b/Makefile index 9a546fa..52f261f 100644 --- a/Makefile +++ b/Makefile @@ -6,11 +6,10 @@ all: CGO_ENABLED=0 go build -o yt-dlp-webui main.go multiarch: - CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -o yt-dlp-webui_linux-arm main.go - CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o yt-dlp-webui_linux-arm64 main.go - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o yt-dlp-webui_linux-amd64 main.go mkdir -p build - mv yt-dlp-webui* build + CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -o build/yt-dlp-webui_linux-arm main.go + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o build/yt-dlp-webui_linux-arm64 main.go + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/yt-dlp-webui_linux-amd64 main.go clean: rm -rf build \ No newline at end of file diff --git a/main.go b/main.go index 619be60..4a431f7 100644 --- a/main.go +++ b/main.go @@ -14,11 +14,12 @@ import ( ) var ( - port int - queueSize int - configFile string - downloadPath string - downloaderPath string + port int + queueSize int + configFile string + downloadPath string + downloaderPath string + sessionFilePath string requireAuth bool username string @@ -40,6 +41,7 @@ func init() { flag.StringVar(&configFile, "conf", "./config.yml", "Config file path") flag.StringVar(&downloadPath, "out", ".", "Where files will be saved") flag.StringVar(&downloaderPath, "driver", "yt-dlp", "yt-dlp executable path") + flag.StringVar(&sessionFilePath, "session", ".", "session file path") flag.BoolVar(&requireAuth, "auth", false, "Enable RPC authentication") flag.StringVar(&username, "user", userFromEnv, "Username required for auth") diff --git a/server/config/parser.go b/server/config/parser.go index 7e826b7..7107573 100644 --- a/server/config/parser.go +++ b/server/config/parser.go @@ -10,13 +10,14 @@ import ( var lock sync.Mutex type serverConfig struct { - Port int `yaml:"port"` - DownloadPath string `yaml:"downloadPath"` - DownloaderPath string `yaml:"downloaderPath"` - RequireAuth bool `yaml:"require_auth"` - Username string `yaml:"username"` - Password string `yaml:"password"` - QueueSize int `yaml:"queue_size"` + Port int `yaml:"port"` + DownloadPath string `yaml:"downloadPath"` + DownloaderPath string `yaml:"downloaderPath"` + RequireAuth bool `yaml:"require_auth"` + Username string `yaml:"username"` + Password string `yaml:"password"` + QueueSize int `yaml:"queue_size"` + SessionFilePath string `yaml:"session_file_path"` } type config struct { @@ -68,6 +69,10 @@ func (c *config) QueueSize(size int) { c.cfg.QueueSize = size } +func (c *config) SessionFilePath(path string) { + c.cfg.SessionFilePath = path +} + var instance *config func Instance() *config { diff --git a/server/internal/memory_db.go b/server/internal/memory_db.go index 5c90b63..0fac2d1 100644 --- a/server/internal/memory_db.go +++ b/server/internal/memory_db.go @@ -6,10 +6,12 @@ import ( "fmt" "log" "os" + "path/filepath" "sync" "github.com/google/uuid" "github.com/marcopeocchi/yt-dlp-web-ui/server/cli" + "github.com/marcopeocchi/yt-dlp-web-ui/server/config" ) // In-Memory Thread-Safe Key-Value Storage with optional persistence @@ -93,7 +95,12 @@ func (m *MemoryDB) All() *[]ProcessResponse { func (m *MemoryDB) Persist() { running := m.All() - fd, err := os.Create("session.dat") + sessionFile := filepath.Join( + config.Instance().GetConfig().SessionFilePath, + "session.dat", + ) + + fd, err := os.Create(sessionFile) if err != nil { log.Println(cli.Red, "Failed to persist session", cli.Reset) }