From 8b5af676474871508dc73ff4e60b625705ac3dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deluan=20Quint=C3=A3o?= Date: Wed, 16 Oct 2024 10:59:22 -0400 Subject: [PATCH] feat(subsonic): support OS clearing play queue (#3399) --- persistence/playqueue_repository.go | 3 +++ server/subsonic/bookmarks.go | 14 +++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/persistence/playqueue_repository.go b/persistence/playqueue_repository.go index e450508bcc1..fe42dd7fcd5 100644 --- a/persistence/playqueue_repository.go +++ b/persistence/playqueue_repository.go @@ -42,6 +42,9 @@ func (r *playQueueRepository) Store(q *model.PlayQueue) error { log.Error(r.ctx, "Error deleting previous playqueue", "user", u.UserName, err) return err } + if len(q.Items) == 0 { + return nil + } pq := r.fromModel(q) if pq.ID == "" { pq.CreatedAt = time.Now() diff --git a/server/subsonic/bookmarks.go b/server/subsonic/bookmarks.go index 42fe9e1769c..69c303147b9 100644 --- a/server/subsonic/bookmarks.go +++ b/server/subsonic/bookmarks.go @@ -1,6 +1,7 @@ package subsonic import ( + "errors" "net/http" "time" @@ -73,9 +74,12 @@ func (api *Router) GetPlayQueue(r *http.Request) (*responses.Subsonic, error) { repo := api.ds.PlayQueue(r.Context()) pq, err := repo.Retrieve(user.ID) - if err != nil { + if err != nil && !errors.Is(err, model.ErrNotFound) { return nil, err } + if pq == nil || len(pq.Items) == 0 { + return newResponse(), nil + } response := newResponse() response.PlayQueue = &responses.PlayQueue{ @@ -91,11 +95,7 @@ func (api *Router) GetPlayQueue(r *http.Request) (*responses.Subsonic, error) { func (api *Router) SavePlayQueue(r *http.Request) (*responses.Subsonic, error) { p := req.Params(r) - ids, err := p.Strings("id") - if err != nil { - return nil, err - } - + ids, _ := p.Strings("id") current, _ := p.String("current") position := p.Int64Or("position", 0) @@ -118,7 +118,7 @@ func (api *Router) SavePlayQueue(r *http.Request) (*responses.Subsonic, error) { } repo := api.ds.PlayQueue(r.Context()) - err = repo.Store(pq) + err := repo.Store(pq) if err != nil { return nil, err }