add releases page; fix HUGE static file perf regression
This commit is contained in:
parent
31fd5da44b
commit
065a34a744
20 changed files with 233 additions and 73 deletions
|
|
@ -3,6 +3,7 @@ package admin
|
|||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"arimelody-web/admin/templates"
|
||||
|
|
@ -10,11 +11,52 @@ import (
|
|||
"arimelody-web/model"
|
||||
)
|
||||
|
||||
func serveRelease(app *model.AppState) http.Handler {
|
||||
func serveReleases(app *model.AppState) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
slices := strings.Split(r.URL.Path[1:], "/")
|
||||
slices := strings.Split(strings.TrimPrefix(r.URL.Path, "/releases")[1:], "/")
|
||||
releaseID := slices[0]
|
||||
|
||||
var action string = ""
|
||||
if len(slices) > 1 {
|
||||
action = slices[1]
|
||||
}
|
||||
|
||||
if len(releaseID) > 0 {
|
||||
serveRelease(app, releaseID, action).ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
session := r.Context().Value("session").(*model.Session)
|
||||
|
||||
type ReleasesData struct {
|
||||
adminPageData
|
||||
Releases []*model.Release
|
||||
}
|
||||
|
||||
releases, err := controller.GetAllReleases(app.DB, false, 0, true)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to pull releases: %s\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
err = templates.ReleasesTemplate.Execute(w, ReleasesData{
|
||||
adminPageData: adminPageData{
|
||||
Path: r.URL.Path,
|
||||
Session: session,
|
||||
},
|
||||
Releases: releases,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to render releases page: %s\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func serveRelease(app *model.AppState, releaseID string, action 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)
|
||||
|
|
@ -28,8 +70,8 @@ func serveRelease(app *model.AppState) http.Handler {
|
|||
return
|
||||
}
|
||||
|
||||
if len(slices) > 1 {
|
||||
switch slices[1] {
|
||||
if len(action) > 0 {
|
||||
switch action {
|
||||
case "editcredits":
|
||||
serveEditCredits(release).ServeHTTP(w, r)
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue