add release credits update UI

Signed-off-by: ari melody <ari@arimelody.me>
This commit is contained in:
ari melody 2024-08-23 23:08:28 +01:00
parent 7914fba52a
commit 34cddcfdb2
27 changed files with 630 additions and 340 deletions

View file

@ -85,9 +85,9 @@ func MustAuthorise(next http.Handler) http.Handler {
}
func GetSession(r *http.Request) *Session {
// if ADMIN_BYPASS {
// return &Session{}
// }
if ADMIN_BYPASS {
return &Session{}
}
var token = ""
// is the session token in context?
@ -177,22 +177,13 @@ func LoginHandler() http.Handler {
cookie.Name = "token"
cookie.Value = session.Token
cookie.Expires = time.Now().Add(24 * time.Hour)
// TODO: uncomment this probably that might be nice i think
// cookie.Secure = true
cookie.HttpOnly = true
cookie.Path = "/"
http.SetCookie(w, &cookie)
serveTemplate("login.html", loginData{Token: session.Token}).ServeHTTP(w, r)
// w.WriteHeader(http.StatusOK)
// w.Header().Add("Content-Type", "text/html")
// w.Write([]byte(
// "<!DOCTYPE html><html><head>"+
// "<meta http-equiv=\"refresh\" content=\"5;url=/admin/\" />"+
// "</head><body>"+
// "Logged in successfully. "+
// "You should be redirected to <a href=\"/admin/\">/admin/</a> in 5 seconds."+
// "</body></html>"),
// )
})
}
@ -255,6 +246,39 @@ func serveTemplate(page string, data any) http.Handler {
})
}
func serveComponent(page string, data any) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fp := filepath.Join("admin", "components", filepath.Clean(page))
info, err := os.Stat(fp)
if err != nil {
if os.IsNotExist(err) {
http.NotFound(w, r)
return
}
}
if info.IsDir() {
http.NotFound(w, r)
return
}
template, err := template.ParseFiles(fp)
if err != nil {
fmt.Printf("Error parsing template files: %s\n", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
err = template.Execute(w, data);
if err != nil {
fmt.Printf("Error executing template: %s\n", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
})
}
func staticHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
info, err := os.Stat(filepath.Join("admin", "static", filepath.Clean(r.URL.Path)))