Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added error case for when DownloadEpisode is called via API and podcast is already downloaded #213

Closed
wants to merge 11 commits into from
4 changes: 4 additions & 0 deletions podcasts/podcasts.go
Expand Up @@ -358,6 +358,10 @@ func (p *Podcasts) DownloadEpisode(episodeID int) error {
log.Printf("Already downloading podcast episode with id %d", episodeID)
return nil
}
if podcastEpisode.Status == db.PodcastEpisodeStatusCompleted {
log.Printf("Already downloaded podcast episode with id %d", episodeID)
return nil
}
podcastEpisode.Status = db.PodcastEpisodeStatusDownloading
p.db.Save(&podcastEpisode)
// nolint: bodyclose
Expand Down
8 changes: 7 additions & 1 deletion server/ctrlbase/ctrl.go
Expand Up @@ -56,8 +56,14 @@ func (c *Controller) Path(rel string) string {
}

func (c *Controller) BaseURL(r *http.Request) string {
var protocol string
if r.TLS == nil {
protocol = "http"
} else {
protocol = "https"
}
scheme := firstExisting(
"http", // fallback
protocol, // fallback
r.Header.Get("X-Forwarded-Proto"),
r.Header.Get("X-Forwarded-Scheme"),
r.URL.Scheme,
Expand Down
2 changes: 1 addition & 1 deletion server/ctrlsubsonic/handlers_common.go
Expand Up @@ -54,7 +54,7 @@ func (c *Controller) ServeScrobble(r *http.Request) *spec.Response {

optStamp := params.GetOrTime("time", time.Now())
optSubmission := params.GetOrBool("submission", true)

if err := streamUpdateStats(c.DB, user.ID, track.Album.ID, optStamp); err != nil {
return spec.NewError(0, "error updating stats: %v", err)
}
Expand Down