Remove tracks from playlist
This commit is contained in:
@@ -109,6 +109,9 @@ func (app *Router) addPlaylistTrackRoute(r chi.Router) {
|
||||
r.Route("/{id}", func(r chi.Router) {
|
||||
r.Use(UrlParams)
|
||||
r.Get("/", wrapper(rest.Get))
|
||||
r.Delete("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
deleteFromPlaylist(app.ds)(w, r)
|
||||
})
|
||||
})
|
||||
r.With(UrlParams).Post("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
addToPlaylist(app.ds)(w, r)
|
||||
|
||||
+25
-1
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/deluan/navidrome/log"
|
||||
"github.com/deluan/navidrome/model"
|
||||
"github.com/deluan/navidrome/utils"
|
||||
)
|
||||
@@ -13,6 +14,29 @@ type addTracksPayload struct {
|
||||
Ids []string `json:"ids"`
|
||||
}
|
||||
|
||||
func deleteFromPlaylist(ds model.DataStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
playlistId := utils.ParamString(r, ":playlistId")
|
||||
id := r.URL.Query().Get(":id")
|
||||
tracksRepo := ds.Playlist(r.Context()).Tracks(playlistId)
|
||||
err := tracksRepo.Delete(id)
|
||||
if err == model.ErrNotFound {
|
||||
log.Warn("Track not found in playlist", "playlistId", playlistId, "id", id)
|
||||
http.Error(w, "not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
log.Error("Error deleting track from playlist", "playlistId", playlistId, "id", id, err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
_, err = w.Write([]byte("{}"))
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func addToPlaylist(ds model.DataStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
playlistId := utils.ParamString(r, ":playlistId")
|
||||
@@ -32,7 +56,7 @@ func addToPlaylist(ds model.DataStore) http.HandlerFunc {
|
||||
// Must return an object with an ID, to satisfy ReactAdmin `create` call
|
||||
_, err = w.Write([]byte(fmt.Sprintf(`{"id":"%s"}`, playlistId)))
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user