diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-05 14:24:23 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-05 14:24:23 +0300 |
| commit | 7bc3b65b3c66c7744e1c6d4fa69842985d06d9b7 (patch) | |
| tree | fa395b13fde18ba42bf7d5b28ad9d630cfa287cc /internal/service/filename.go | |
| parent | ed208d7120b6e6a7c2ce234504228b5a1ba48f11 (diff) | |
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
Diffstat (limited to 'internal/service/filename.go')
| -rw-r--r-- | internal/service/filename.go | 31 |
1 files changed, 31 insertions, 0 deletions
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 + } + } +} |
