Web UI: podcasts, radio, shares, bookmarks pages; admin podcast/jukebox management; per-user Subsonic permission editor
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.noroutes.net/NoRoutes/vibetunes/internal/auth"
|
||||
"git.noroutes.net/NoRoutes/vibetunes/internal/database"
|
||||
)
|
||||
|
||||
func (h *Web) handleBookmarks(w http.ResponseWriter, r *http.Request) {
|
||||
user := auth.UserFromContext(r.Context())
|
||||
bookmarks, err := database.ListBookmarks(h.DB, user.ID)
|
||||
if err != nil {
|
||||
http.Error(w, "internal error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
type bookmarkView struct {
|
||||
Bookmark *database.Bookmark
|
||||
Song SongRow
|
||||
}
|
||||
var views []bookmarkView
|
||||
for _, b := range bookmarks {
|
||||
song, err := database.GetSong(h.DB, b.SongID)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
views = append(views, bookmarkView{Bookmark: b, Song: toSongRow(h.DB, song, albumOf(h.DB, song), user.ID)})
|
||||
}
|
||||
h.page(w, r, "bookmarks", "bookmarks", "Bookmarks", views)
|
||||
}
|
||||
|
||||
func (h *Web) handleBookmarkDelete(w http.ResponseWriter, r *http.Request) {
|
||||
user := auth.UserFromContext(r.Context())
|
||||
songID := r.PathValue("songID")
|
||||
if err := database.DeleteBookmark(h.DB, user.ID, songID); err != nil {
|
||||
http.Error(w, "internal error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, "/bookmarks", http.StatusFound)
|
||||
}
|
||||
Reference in New Issue
Block a user