fix silly admin routing nonsense
This commit is contained in:
parent
09c09b6310
commit
a33e6717e0
6 changed files with 57 additions and 58 deletions
|
|
@ -20,14 +20,14 @@ func Handler(app *model.AppState) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
mux.Handle("/", accountIndexHandler(app))
|
mux.Handle("/account/", accountIndexHandler(app))
|
||||||
|
|
||||||
mux.Handle("/totp-setup", totpSetupHandler(app))
|
mux.Handle("/account/totp-setup", totpSetupHandler(app))
|
||||||
mux.Handle("/totp-confirm", totpConfirmHandler(app))
|
mux.Handle("/account/totp-confirm", totpConfirmHandler(app))
|
||||||
mux.Handle("/totp-delete", totpDeleteHandler(app))
|
mux.Handle("/account/totp-delete", totpDeleteHandler(app))
|
||||||
|
|
||||||
mux.Handle("/password", changePasswordHandler(app))
|
mux.Handle("/account/password", changePasswordHandler(app))
|
||||||
mux.Handle("/delete", deleteAccountHandler(app))
|
mux.Handle("/account/delete", deleteAccountHandler(app))
|
||||||
|
|
||||||
mux.ServeHTTP(w, r)
|
mux.ServeHTTP(w, r)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ func Handler(app *model.AppState) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
mux.Handle("/{id}", serveBlogPost(app))
|
mux.Handle("/blogs/{id}", serveBlogPost(app))
|
||||||
mux.Handle("/", serveBlogIndex(app))
|
mux.Handle("/blogs/", serveBlogIndex(app))
|
||||||
|
|
||||||
mux.ServeHTTP(w, r)
|
mux.ServeHTTP(w, r)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,10 @@ func Handler(app *model.AppState) http.Handler {
|
||||||
mux.Handle("/logout", core.RequireAccount(auth.LogoutHandler(app)))
|
mux.Handle("/logout", core.RequireAccount(auth.LogoutHandler(app)))
|
||||||
|
|
||||||
mux.Handle("/logs", core.RequireAccount(logs.Handler(app)))
|
mux.Handle("/logs", core.RequireAccount(logs.Handler(app)))
|
||||||
mux.Handle("/music/", core.RequireAccount(http.StripPrefix("/music", music.Handler(app))))
|
mux.Handle("/music/", core.RequireAccount(music.Handler(app)))
|
||||||
mux.Handle("/blogs/", core.RequireAccount(http.StripPrefix("/blogs", blog.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) {
|
mux.Handle("/static/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.URL.Path == "/static/admin.css" {
|
if r.URL.Path == "/static/admin.css" {
|
||||||
|
|
|
||||||
|
|
@ -9,17 +9,23 @@ func Handler(app *model.AppState) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
mux := http.NewServeMux()
|
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)
|
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)
|
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)
|
mux.ServeHTTP(w, r)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -13,41 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func serveReleases(app *model.AppState) http.Handler {
|
func serveReleases(app *model.AppState) http.Handler {
|
||||||
mux := http.NewServeMux()
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
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) {
|
|
||||||
session := r.Context().Value("session").(*model.Session)
|
session := r.Context().Value("session").(*model.Session)
|
||||||
|
|
||||||
type ReleasesData struct {
|
type ReleasesData struct {
|
||||||
|
|
@ -75,14 +41,10 @@ func serveReleases(app *model.AppState) http.Handler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return mux
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func serveRelease(app *model.AppState, releaseID string) http.Handler {
|
func serveRelease(app *model.AppState, releaseID string) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
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)
|
release, err := controller.GetRelease(app.DB, releaseID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.Contains(err.Error(), "no rows") {
|
if strings.Contains(err.Error(), "no rows") {
|
||||||
|
|
@ -94,6 +56,8 @@ func serveRelease(app *model.AppState, releaseID string) http.Handler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
session := r.Context().Value("session").(*model.Session)
|
||||||
|
|
||||||
type ReleaseResponse struct {
|
type ReleaseResponse struct {
|
||||||
core.AdminPageData
|
core.AdminPageData
|
||||||
Release *model.Release
|
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 {
|
func serveEditCredits(release *model.Release) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "text/html")
|
w.Header().Set("Content-Type", "text/html")
|
||||||
|
|
|
||||||
|
|
@ -31,13 +31,13 @@
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<p class="section-label">music</p>
|
<p class="section-label">music</p>
|
||||||
<div class="nav-item{{if hasPrefix .Path "/releases"}} active{{end}}">
|
<div class="nav-item{{if hasPrefix .Path "/music/releases"}} active{{end}}">
|
||||||
<a href="/admin/music/releases/">releases</a>
|
<a href="/admin/music/releases/">releases</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="nav-item{{if hasPrefix .Path "/artists"}} active{{end}}">
|
<div class="nav-item{{if hasPrefix .Path "/music/artists"}} active{{end}}">
|
||||||
<a href="/admin/music/artists/">artists</a>
|
<a href="/admin/music/artists/">artists</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="nav-item{{if hasPrefix .Path "/tracks"}} active{{end}}">
|
<div class="nav-item{{if hasPrefix .Path "/music/tracks"}} active{{end}}">
|
||||||
<a href="/admin/music/tracks/">tracks</a>
|
<a href="/admin/music/tracks/">tracks</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue