diff --git a/Dockerfile b/Dockerfile index 0b51d8f..05fcdfc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM docker.io/golang:1.22 as builder +FROM docker.io/golang:1.20 as builder WORKDIR /app diff --git a/flake.lock b/flake.lock index c570239..b110849 100644 --- a/flake.lock +++ b/flake.lock @@ -28,11 +28,11 @@ ] }, "locked": { - "lastModified": 1717050755, - "narHash": "sha256-C9IEHABulv2zEDFA+Bf0E1nmfN4y6MIUe5eM2RCrDC0=", + "lastModified": 1710154385, + "narHash": "sha256-4c3zQ2YY4BZOufaBJB4v9VBBeN2dH7iVdoJw8SDNCfI=", "owner": "tweag", "repo": "gomod2nix", - "rev": "31b6d2e40b36456e792cd6cf50d5a8ddd2fa59a1", + "rev": "872b63ddd28f318489c929d25f1f0a3c6039c971", "type": "github" }, "original": { @@ -43,11 +43,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1720955038, - "narHash": "sha256-GaliJqfFwyYxReFywxAa8orCO+EnDq2NK2F+5aSc8vo=", + "lastModified": 1713284584, + "narHash": "sha256-rRuPBJD9+yjz7tY3xC/BvFUwloutynR9piiVE6fhGqo=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "aa247c0c90ecf4ae7a032c54fdc21b91ca274062", + "rev": "2b6ee326ad047870526d9a3ae88dfd0197da898d", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index bb94005..1338416 100644 --- a/flake.nix +++ b/flake.nix @@ -39,3 +39,4 @@ } ); } + diff --git a/go.mod b/go.mod index 5a4ffed..52f168e 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module gitlab.com/XenGi/sanic -go 1.22 +go 1.21 require ( github.com/fhs/gompd/v2 v2.3.0 diff --git a/mpd.go b/mpd.go index 5e4cf37..8a0e416 100644 --- a/mpd.go +++ b/mpd.go @@ -11,7 +11,6 @@ import ( // MPD API calls -// updateDb Updates the music database: find new files, remove deleted files, update modified files. func updateDb(c echo.Context) error { // Connect to MPD server conn, err := mpd.Dial("tcp", "localhost:6600") @@ -28,7 +27,6 @@ func updateDb(c echo.Context) error { return c.String(http.StatusOK, fmt.Sprintf("Database update started with job id %d", jobId)) } -// previousTrack Plays previous song in the queue. func previousTrack(c echo.Context) error { // Connect to MPD server conn, err := mpd.Dial("tcp", "localhost:6600") @@ -45,7 +43,6 @@ func previousTrack(c echo.Context) error { return c.String(http.StatusOK, "Playing previous track in queue") } -// nextTrack Plays next song in the queue. func nextTrack(c echo.Context) error { // Connect to MPD server conn, err := mpd.Dial("tcp", "localhost:6600") @@ -62,7 +59,6 @@ func nextTrack(c echo.Context) error { return c.String(http.StatusOK, "PLaying next track in queue") } -// stopPlayback Stops playing. func stopPlayback(c echo.Context) error { // Connect to MPD server conn, err := mpd.Dial("tcp", "localhost:6600") @@ -79,7 +75,6 @@ func stopPlayback(c echo.Context) error { return c.String(http.StatusOK, "Playback stopped") } -// resumePlayback Begins playing the playlist or if paused resumes playback. func resumePlayback(c echo.Context) error { // Connect to MPD server conn, err := mpd.Dial("tcp", "localhost:6600") @@ -107,7 +102,6 @@ func resumePlayback(c echo.Context) error { return c.String(http.StatusOK, "Playback resumed") } -// pausePlayback Pauses playback. func pausePlayback(c echo.Context) error { // Connect to MPD server conn, err := mpd.Dial("tcp", "localhost:6600") @@ -124,7 +118,6 @@ func pausePlayback(c echo.Context) error { return c.String(http.StatusOK, "Playback paused") } -// seek Seeks to the position defined by seconds within the current song. func seek(c echo.Context) error { // Connect to MPD server conn, err := mpd.Dial("tcp", "localhost:6600") @@ -151,7 +144,6 @@ func seek(c echo.Context) error { return c.String(http.StatusOK, fmt.Sprintf("Seeked current track to %d seconds", seconds)) } -// toggleRepeat Toggles repeat state between 1 or 0. func toggleRepeat(c echo.Context) error { // Connect to MPD server conn, err := mpd.Dial("tcp", "localhost:6600") @@ -179,7 +171,6 @@ func toggleRepeat(c echo.Context) error { return c.String(http.StatusOK, msg) } -// toggleRandom Toggles random state between 1 or 0. func toggleRandom(c echo.Context) error { // Connect to MPD server conn, err := mpd.Dial("tcp", "localhost:6600") @@ -207,7 +198,6 @@ func toggleRandom(c echo.Context) error { return c.String(http.StatusOK, msg) } -// setVolume Sets volume to level, the range of volume is 0-100. func setVolume(c echo.Context) error { // Connect to MPD server conn, err := mpd.Dial("tcp", "localhost:6600") @@ -235,7 +225,6 @@ func setVolume(c echo.Context) error { // Queue -// deleteTrackFromQueue removed track with song_id from queue func deleteTrackFromQueue(c echo.Context) error { // Connect to MPD server conn, err := mpd.Dial("tcp", "localhost:6600") @@ -258,7 +247,6 @@ func deleteTrackFromQueue(c echo.Context) error { return c.String(http.StatusOK, fmt.Sprintf("Removed song %d from queue", songId)) } -// moveTrackInQueue moves song with song_id to the new place position in the queue. func moveTrackInQueue(c echo.Context) error { // Connect to MPD server conn, err := mpd.Dial("tcp", "localhost:6600") @@ -286,7 +274,6 @@ func moveTrackInQueue(c echo.Context) error { return c.String(http.StatusOK, fmt.Sprintf("Moved song %d to position %d", songId, position)) } -// attachPlaylist adds the playlist with the name playlist_name to the queue. func attachPlaylist(c echo.Context) error { // Connect to MPD server conn, err := mpd.Dial("tcp", "localhost:6600") @@ -306,7 +293,6 @@ func attachPlaylist(c echo.Context) error { return c.JSON(http.StatusOK, "") } -// replaceQueue replaces the current queue with the playlist with the name playlist_name. func replaceQueue(c echo.Context) error { // Connect to MPD server conn, err := mpd.Dial("tcp", "localhost:6600") @@ -333,7 +319,6 @@ func replaceQueue(c echo.Context) error { // Playlists -// listPlaylists return a list of all stored playlists. func listPlaylists(c echo.Context) error { // Connect to MPD server conn, err := mpd.Dial("tcp", "localhost:6600") @@ -351,7 +336,6 @@ func listPlaylists(c echo.Context) error { return c.JSON(http.StatusOK, playlists) } -// listPlaylist returns the contents of the playlist defined by name. func listPlaylist(c echo.Context) error { // Connect to MPD server conn, err := mpd.Dial("tcp", "localhost:6600") @@ -371,7 +355,6 @@ func listPlaylist(c echo.Context) error { return c.JSON(http.StatusOK, playlist) } -// deletePlaylist deletes the playlist defined by name. func deletePlaylist(c echo.Context) error { // Connect to MPD server conn, err := mpd.Dial("tcp", "localhost:6600") @@ -391,7 +374,6 @@ func deletePlaylist(c echo.Context) error { return c.String(http.StatusNoContent, "") } -// savePlaylist saves the current queue to a playlist with the given name. func savePlaylist(c echo.Context) error { // Connect to MPD server conn, err := mpd.Dial("tcp", "localhost:6600") @@ -411,7 +393,6 @@ func savePlaylist(c echo.Context) error { return c.String(http.StatusCreated, "") } -// searchDatabase search the database path given by pattern and returns all entries that contain the pattern either in their artist, album or title. func searchDatabase(c echo.Context) error { // Connect to MPD server conn, err := mpd.Dial("tcp", "localhost:6600") diff --git a/server.go b/server.go index ae2e3c8..d145897 100644 --- a/server.go +++ b/server.go @@ -16,7 +16,6 @@ import ( "strings" ) -// Config holds the configuration for the mpd connection and for the web server. type Config struct { MPD struct { Hostname string `ini:"hostname"` @@ -113,7 +112,6 @@ func main() { } } -// wsServe handles websocket connections. func wsServe(c echo.Context) error { websocket.Handler(func(ws *websocket.Conn) { defer ws.Close() @@ -184,7 +182,6 @@ func wsServe(c echo.Context) error { return nil } -// downloadTrack tries to download a given URL and saves the song to the database. func downloadTrack(c echo.Context) error { // yt-dlp \ // --no-wait-for-video \ diff --git a/static/index.html b/static/index.html index 31b34ce..15584db 100644 --- a/static/index.html +++ b/static/index.html @@ -200,8 +200,7 @@
- - + diff --git a/static/index.js b/static/index.js index c2c7c37..dcc6a1e 100644 --- a/static/index.js +++ b/static/index.js @@ -33,7 +33,6 @@ const tab_browser = document.getElementById("tab-browser"); const tab_search = document.getElementById("tab-search"); const tab_playlists = document.getElementById("tab-playlists"); const control_playlist_list = document.getElementById("control-playlist-list"); -const control_refresh_playlists = document.getElementById("control-refresh-playlists"); const control_replace_playlist = document.getElementById("control-replace-playlist"); const control_attach_playlist = document.getElementById("control-attach-playlist"); const control_save_playlist = document.getElementById("control-save-playlist"); @@ -84,7 +83,9 @@ refreshPlaylists = () => { option.value = p["playlist"]; option.addEventListener("click", () => { fetch(`${API_URL}/playlists/${p["playlist"]}`).then(async r => { - if (r.status === 200) fillResultTable(await r.json()); + if (r.status === 200) { + fillResultTable(await r.json()); + } }) }); control_playlist_list.appendChild(option) @@ -171,10 +172,6 @@ control_search_submit.addEventListener("click", event => { }) }); -control_refresh_playlists.addEventListener("click", () => { - refreshPlaylists(); -}); - control_replace_playlist.addEventListener("click", () => { fetch(`${API_URL}/queue/replace/${control_playlist_list.value}`).then(async r => { if (r.status !== 200) {