add remove track from queue
This commit is contained in:
parent
7d56123998
commit
79a6049a91
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -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
24
mpd.go
|
@ -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, "")
|
||||
}
|
||||
|
|
|
@ -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
4
static/controls.js
vendored
|
@ -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());
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue