fix(podcast): gracefully handle no podcast cover URL (#547)

* fix(podcast): nil pointer when podcast has no image

* don't download empty cover string

---------

Co-authored-by: sentriz <senan@senan.xyz>
This commit is contained in:
Chad Clark
2024-11-16 14:41:40 +00:00
committed by GitHub
co-authored by sentriz
parent 643ffffa0f
commit aef5f920d2
+8 -1
View File
@@ -82,11 +82,14 @@ func (p *Podcasts) AddNewPodcast(rssURL string, feed *gofeed.Feed) (*db.Podcast,
}
podcast := db.Podcast{
Description: feed.Description,
ImageURL: feed.Image.URL,
ImageURL: "",
Title: feed.Title,
URL: rssURL,
RootDir: rootDir,
}
if feed.Image != nil {
podcast.ImageURL = feed.Image.URL
}
if err := os.Mkdir(podcast.RootDir, 0o755); err != nil && !os.IsExist(err) {
return nil, err
}
@@ -316,6 +319,10 @@ func getPodcastEpisodeFilename(podcast *db.Podcast, podcastEpisode *db.PodcastEp
}
func (p *Podcasts) downloadPodcastCover(podcast *db.Podcast) error {
if podcast.ImageURL == "" {
return nil
}
imageURL, err := url.Parse(podcast.ImageURL)
if err != nil {
return fmt.Errorf("parse image url: %w", err)