From 7bc3b65b3c66c7744e1c6d4fa69842985d06d9b7 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 5 May 2026 14:24:23 +0300 Subject: Fix podcast support critical bugs from code review - Fix boolean scanning from SQLite INTEGER columns (intToBool helper) - Fix BrowseSet LIMIT 0 returning zero episodes (use 1000 instead) - Fix checkFeed double-fetch by parsing from resp.Body directly + Add ParseFeedReader for body reuse - Fix file handle leak in DownloadEpisode (explicit Close before ImportMediaFile) - Fix incomplete rollback in DownloadEpisode (remove file + delete media row) - Fix 204 No Content handler writing 'null' body - Fix DownloadCoverImage to accept *http.Client with timeout - Deduplicate uniqueFilename into shared internal/service/filename.go - Wire frontend renderPodcastEpisodes into renderBrowse from API data - Refactor podcasts.js: remove extra API call, fix toggle toast, remove duplicate toast - Add Config.PodcastCheckMinutes + PODCAST_CHECK_INTERVAL_MINUTES env var - Start background CheckFeeds goroutine in main.go with ticker - Update NewPodcastService to accept checkInterval parameter - Log errors from CheckFeeds and episode creation instead of silently discarding --- internal/service/filename.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 internal/service/filename.go (limited to 'internal/service/filename.go') diff --git a/internal/service/filename.go b/internal/service/filename.go new file mode 100644 index 0000000..9303de6 --- /dev/null +++ b/internal/service/filename.go @@ -0,0 +1,31 @@ +package service + +import ( + "fmt" + "os" + "path/filepath" + "strings" +) + +// uniqueFilename returns a non-conflicting full path by appending (n) +// if a file with the same name already exists in dir. +func uniqueFilename(dir, filename string) string { + filename = filepath.Base(filename) + if filename == "." || filename == ".." || filename == "" { + return "" + } + ext := filepath.Ext(filename) + base := strings.TrimSuffix(filename, ext) + + candidate := filepath.Join(dir, filename) + if _, err := os.Stat(candidate); os.IsNotExist(err) { + return candidate + } + + for i := 1; ; i++ { + candidate = filepath.Join(dir, fmt.Sprintf("%s(%d)%s", base, i, ext)) + if _, err := os.Stat(candidate); os.IsNotExist(err) { + return candidate + } + } +} -- cgit v1.2.3