diff --git a/admin/account/accounthttp.go b/admin/account/accounthttp.go index a826a1b..4595cd4 100644 --- a/admin/account/accounthttp.go +++ b/admin/account/accounthttp.go @@ -20,14 +20,14 @@ func Handler(app *model.AppState) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { mux := http.NewServeMux() - mux.Handle("/", accountIndexHandler(app)) + mux.Handle("/account/", accountIndexHandler(app)) - mux.Handle("/totp-setup", totpSetupHandler(app)) - mux.Handle("/totp-confirm", totpConfirmHandler(app)) - mux.Handle("/totp-delete", totpDeleteHandler(app)) + mux.Handle("/account/totp-setup", totpSetupHandler(app)) + mux.Handle("/account/totp-confirm", totpConfirmHandler(app)) + mux.Handle("/account/totp-delete", totpDeleteHandler(app)) - mux.Handle("/password", changePasswordHandler(app)) - mux.Handle("/delete", deleteAccountHandler(app)) + mux.Handle("/account/password", changePasswordHandler(app)) + mux.Handle("/account/delete", deleteAccountHandler(app)) mux.ServeHTTP(w, r) }) diff --git a/admin/blog/blog.go b/admin/blog/blog.go index d03907a..d1a2922 100644 --- a/admin/blog/blog.go +++ b/admin/blog/blog.go @@ -15,8 +15,8 @@ func Handler(app *model.AppState) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { mux := http.NewServeMux() - mux.Handle("/{id}", serveBlogPost(app)) - mux.Handle("/", serveBlogIndex(app)) + mux.Handle("/blogs/{id}", serveBlogPost(app)) + mux.Handle("/blogs/", serveBlogIndex(app)) mux.ServeHTTP(w, r) }) diff --git a/admin/http.go b/admin/http.go index 33f017b..e913558 100644 --- a/admin/http.go +++ b/admin/http.go @@ -26,10 +26,10 @@ func Handler(app *model.AppState) http.Handler { mux.Handle("/logout", core.RequireAccount(auth.LogoutHandler(app))) mux.Handle("/logs", core.RequireAccount(logs.Handler(app))) - mux.Handle("/music/", core.RequireAccount(http.StripPrefix("/music", music.Handler(app)))) - mux.Handle("/blogs/", core.RequireAccount(http.StripPrefix("/blogs", blog.Handler(app)))) + mux.Handle("/music/", core.RequireAccount(music.Handler(app))) + mux.Handle("/blogs/", core.RequireAccount(blog.Handler(app))) - mux.Handle("/account/", core.RequireAccount(http.StripPrefix("/account", account.Handler(app)))) + mux.Handle("/account/", core.RequireAccount(account.Handler(app))) mux.Handle("/static/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/static/admin.css" { diff --git a/admin/music/musichttp.go b/admin/music/musichttp.go index 607026e..562d83f 100644 --- a/admin/music/musichttp.go +++ b/admin/music/musichttp.go @@ -9,17 +9,23 @@ func Handler(app *model.AppState) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { mux := http.NewServeMux() - mux.Handle("/releases/", http.StripPrefix("/releases", serveReleases(app))) + mux.HandleFunc("/music/releases/{id}/", func(w http.ResponseWriter, r *http.Request) { + serveEditRelease(app, r.PathValue("id")).ServeHTTP(w, r) + }) + mux.HandleFunc("/music/releases/{id}", func(w http.ResponseWriter, r *http.Request) { + serveRelease(app, r.PathValue("id")).ServeHTTP(w, r) + }) + mux.Handle("/music/releases/", serveReleases(app)) - mux.HandleFunc("/artists/{id}", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/music/artists/{id}", func(w http.ResponseWriter, r *http.Request) { serveArtist(app, r.PathValue("id")).ServeHTTP(w, r) }) - mux.Handle("/artists/", http.StripPrefix("/artists", serveArtists(app))) + mux.Handle("/music/artists/", serveArtists(app)) - mux.HandleFunc("/tracks/{id}", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/music/tracks/{id}", func(w http.ResponseWriter, r *http.Request) { serveTrack(app, r.PathValue("id")).ServeHTTP(w, r) }) - mux.Handle("/tracks/", http.StripPrefix("/tracks", serveTracks(app))) + mux.Handle("/music/tracks/", serveTracks(app)) mux.ServeHTTP(w, r) }) diff --git a/admin/music/releasehttp.go b/admin/music/releasehttp.go index bc41602..f3c9dd8 100644 --- a/admin/music/releasehttp.go +++ b/admin/music/releasehttp.go @@ -13,41 +13,7 @@ import ( ) func serveReleases(app *model.AppState) http.Handler { - mux := http.NewServeMux() - - mux.HandleFunc("/{id}/", func(w http.ResponseWriter, r *http.Request) { - releaseID := r.PathValue("id") - release, err := controller.GetRelease(app.DB, releaseID, true) - if err != nil { - if strings.Contains(err.Error(), "no rows") { - http.NotFound(w, r) - return - } - fmt.Fprintf(os.Stderr, "WARN: Failed to fetch full release data for %s: %s\n", releaseID, err) - http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) - return - } - - mux := http.NewServeMux() - - mux.Handle("/{id}/editcredits", serveEditCredits(release)) - mux.Handle("/{id}/addcredit", serveAddCredit(app, release)) - mux.Handle("/{id}/newcredit", serveNewCredit(app)) - - mux.Handle("/{id}/editlinks", serveEditLinks(release)) - - mux.Handle("/{id}/edittracks", serveEditTracks(release)) - mux.Handle("/{id}/addtrack", serveAddTrack(app, release)) - mux.Handle("/{id}/newtrack", serveNewTrack(app)) - - mux.ServeHTTP(w, r) - }) - - mux.HandleFunc("/{id}", func(w http.ResponseWriter, r *http.Request) { - serveRelease(app, r.PathValue("id")).ServeHTTP(w, r) - }) - - mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { session := r.Context().Value("session").(*model.Session) type ReleasesData struct { @@ -75,14 +41,10 @@ func serveReleases(app *model.AppState) http.Handler { return } }) - - return mux } func serveRelease(app *model.AppState, releaseID string) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - session := r.Context().Value("session").(*model.Session) - release, err := controller.GetRelease(app.DB, releaseID, true) if err != nil { if strings.Contains(err.Error(), "no rows") { @@ -94,6 +56,8 @@ func serveRelease(app *model.AppState, releaseID string) http.Handler { return } + session := r.Context().Value("session").(*model.Session) + type ReleaseResponse struct { core.AdminPageData Release *model.Release @@ -112,6 +76,35 @@ func serveRelease(app *model.AppState, releaseID string) http.Handler { }) } +func serveEditRelease(app *model.AppState, releaseID string) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + release, err := controller.GetRelease(app.DB, releaseID, true) + if err != nil { + if strings.Contains(err.Error(), "no rows") { + http.NotFound(w, r) + return + } + fmt.Fprintf(os.Stderr, "WARN: Failed to fetch full release data for %s: %s\n", releaseID, err) + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + return + } + + mux := http.NewServeMux() + + mux.Handle("/music/releases/{id}/editcredits", serveEditCredits(release)) + mux.Handle("/music/releases/{id}/addcredit", serveAddCredit(app, release)) + mux.Handle("/music/releases/{id}/newcredit", serveNewCredit(app)) + + mux.Handle("/music/releases/{id}/editlinks", serveEditLinks(release)) + + mux.Handle("/music/releases/{id}/edittracks", serveEditTracks(release)) + mux.Handle("/music/releases/{id}/addtrack", serveAddTrack(app, release)) + mux.Handle("/music/releases/{id}/newtrack", serveNewTrack(app)) + + mux.ServeHTTP(w, r) + }) +} + func serveEditCredits(release *model.Release) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") diff --git a/admin/templates/html/layout.html b/admin/templates/html/layout.html index 1e052a5..9f32eaa 100644 --- a/admin/templates/html/layout.html +++ b/admin/templates/html/layout.html @@ -31,13 +31,13 @@

music

-