add remove track from queue

This commit is contained in:
XenGi 2024-04-06 15:28:00 +02:00
parent 7d56123998
commit 79a6049a91
Signed by: xengi
SSH key fingerprint: SHA256:FGp51kRvGOcWnTHiOI39ImwVO4A3fpvR30nPX3LpV7g
4 changed files with 30 additions and 2 deletions

2
.gitignore vendored
View file

@ -3,6 +3,8 @@ result
# self-signed certs for testing
cert.pem
key.pem
# test files
*.mp3
# Created by https://www.toptal.com/developers/gitignore/api/linux,windows,macos,vim,goland+all,go,direnv
# Edit at https://www.toptal.com/developers/gitignore?templates=linux,windows,macos,vim,goland+all,go,direnv

24
mpd.go
View file

@ -214,3 +214,27 @@ func setVolume(c echo.Context) error {
return c.String(http.StatusOK, "")
}
// Queue
func deleteTrackFromQueue(c echo.Context) error {
// Connect to MPD server
conn, err := mpd.Dial("tcp", "localhost:6600")
if err != nil {
c.Logger().Error(err)
}
defer conn.Close()
songId, err := strconv.Atoi(c.Param("song_id"))
if err != nil {
c.Logger().Error(err)
}
err = conn.DeleteID(songId)
if err != nil {
c.Logger().Error(err)
return c.String(http.StatusBadRequest, err.Error())
}
return c.String(http.StatusOK, "")
}

View file

@ -89,6 +89,8 @@ func main() {
g.GET("/random", toggleRandom)
g.GET("/volume/:level", setVolume)
g.GET("/queue/delete/:song_id", deleteTrackFromQueue)
g.GET("/download", downloadTrack)
e.GET("/ws", wsServe)

4
static/controls.js vendored
View file

@ -406,8 +406,8 @@ socket.addEventListener("message", (e) => {
remove.classList.add("borderless");
remove.innerHTML = "❌"; // ❌ Cross mark
remove.addEventListener("click", event => {
console.log(`DEBUG: remove song ${elem.Pos} from queue`);
fetch(`${API_URL}/queue_del/${elem.Pos}`).then(r => {
console.log(`DEBUG: remove song id ${elem.Id} from queue`);
fetch(`${API_URL}/queue/delete/${elem.Id}`).then(r => {
console.log(r.text());
});
});