Skip to content

Commit

Permalink
feat(subsonic): support OS clearing play queue (#3399)
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan authored Oct 16, 2024
1 parent 00c6a0e commit 8b5af67
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 3 additions & 0 deletions persistence/playqueue_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 7 additions & 7 deletions server/subsonic/bookmarks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package subsonic

import (
"errors"
"net/http"
"time"

Expand Down Expand Up @@ -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{
Expand All @@ -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)

Expand All @@ -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
}
Expand Down

0 comments on commit 8b5af67

Please sign in to comment.