Minor cleanups

This commit is contained in:
Dominic Ferrando
2025-04-24 00:29:10 -04:00
parent 27fc9476fa
commit 73d66560b6
5 changed files with 11 additions and 17 deletions
-4
View File
@@ -16,10 +16,6 @@ var (
)
func IsAdminSessionValid(token string) bool {
if DevMode {
return true
}
AdminMutex.RLock()
session, exists := AdminSessions[token]
AdminMutex.RUnlock()
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"strings"
)
const DevMode = false
const DevMode = true
func FormatBytes(bytes int64) string {
const (
+1 -11
View File
@@ -25,7 +25,7 @@ import (
func AdminOnlyMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
c, err := r.Cookie("comfy_admin")
if err != nil || !util.IsAdminSessionValid(c.Value) {
if !util.DevMode && (err != nil || !util.IsAdminSessionValid(c.Value)) {
// Check if it's an HTMX request
if r.Header.Get("HX-Request") == "true" {
w.Header().Set("HX-Redirect", "/authorize")
@@ -496,16 +496,6 @@ func main() {
})
r.Get("/authorized", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
if c, err := r.Cookie("comfy_admin"); err == nil && util.IsAdminSessionValid(c.Value) {
w.Write([]byte("true"))
} else {
w.Write([]byte("false"))
}
})
r.Route("/admin", func(r chi.Router) {
r.Use(AdminOnlyMiddleware)
+4
View File
@@ -108,3 +108,7 @@ function applyCatalogSearch() {
function currentBoardSlug() {
return window.location.pathname.split("/")[1] || "";
}
function getCurrentDateISOString() {
return (new Date()).toISOString().slice(0, 16)
}
+5 -1
View File
@@ -48,7 +48,11 @@ templ PostAdminDialog(post database.Post) {
</div>
<div>
<span>Days: </span>
<input type="datetime-local" name="expiration"/>
<input
_="on load set my.value to getCurrentDateISOString() then set my.min to my.value"
type="datetime-local"
name="expiration"
/>
</div>
<button
type="submit"