add list playlists
This commit is contained in:
parent
79a6049a91
commit
bddc82399b
19
mpd.go
19
mpd.go
|
@ -238,3 +238,22 @@ func deleteTrackFromQueue(c echo.Context) error {
|
||||||
|
|
||||||
return c.String(http.StatusOK, "")
|
return c.String(http.StatusOK, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Playlists
|
||||||
|
|
||||||
|
func listPlaylists(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()
|
||||||
|
|
||||||
|
playlists, err := conn.ListPlaylists()
|
||||||
|
if err != nil {
|
||||||
|
c.Logger().Error(err)
|
||||||
|
return c.String(http.StatusBadRequest, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(http.StatusOK, playlists)
|
||||||
|
}
|
||||||
|
|
|
@ -91,6 +91,8 @@ func main() {
|
||||||
|
|
||||||
g.GET("/queue/delete/:song_id", deleteTrackFromQueue)
|
g.GET("/queue/delete/:song_id", deleteTrackFromQueue)
|
||||||
|
|
||||||
|
g.GET("/playlists", listPlaylists)
|
||||||
|
|
||||||
g.GET("/download", downloadTrack)
|
g.GET("/download", downloadTrack)
|
||||||
|
|
||||||
e.GET("/ws", wsServe)
|
e.GET("/ws", wsServe)
|
||||||
|
|
12
static/controls.js
vendored
12
static/controls.js
vendored
|
@ -106,6 +106,18 @@ tab_search.addEventListener("click", e => {
|
||||||
});
|
});
|
||||||
|
|
||||||
tab_playlists.addEventListener("click", e => {
|
tab_playlists.addEventListener("click", e => {
|
||||||
|
fetch(`${API_URL}/playlists`).then(async r => {
|
||||||
|
if (r.status === 200) {
|
||||||
|
const playlists = await r.json();
|
||||||
|
control_playlist_list.options.length = 0; // clear playlists
|
||||||
|
playlists.forEach(p => {
|
||||||
|
const option = document.createElement("option")
|
||||||
|
option.appendChild(document.createTextNode(p["playlist"]));
|
||||||
|
option.value = p["playlist"];
|
||||||
|
control_playlist_list.appendChild(option)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
if (!tab_playlists.classList.contains("active")) {
|
if (!tab_playlists.classList.contains("active")) {
|
||||||
tab_browser.classList.remove("active");
|
tab_browser.classList.remove("active");
|
||||||
tab_search.classList.remove("active")
|
tab_search.classList.remove("active")
|
||||||
|
|
Loading…
Reference in a new issue