Minor cleanups
This commit is contained in:
@@ -16,10 +16,6 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func IsAdminSessionValid(token string) bool {
|
func IsAdminSessionValid(token string) bool {
|
||||||
if DevMode {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
AdminMutex.RLock()
|
AdminMutex.RLock()
|
||||||
session, exists := AdminSessions[token]
|
session, exists := AdminSessions[token]
|
||||||
AdminMutex.RUnlock()
|
AdminMutex.RUnlock()
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DevMode = false
|
const DevMode = true
|
||||||
|
|
||||||
func FormatBytes(bytes int64) string {
|
func FormatBytes(bytes int64) string {
|
||||||
const (
|
const (
|
||||||
|
|||||||
+1
-11
@@ -25,7 +25,7 @@ import (
|
|||||||
func AdminOnlyMiddleware(next http.Handler) http.Handler {
|
func AdminOnlyMiddleware(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
c, err := r.Cookie("comfy_admin")
|
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
|
// Check if it's an HTMX request
|
||||||
if r.Header.Get("HX-Request") == "true" {
|
if r.Header.Get("HX-Request") == "true" {
|
||||||
w.Header().Set("HX-Redirect", "/authorize")
|
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.Route("/admin", func(r chi.Router) {
|
||||||
r.Use(AdminOnlyMiddleware)
|
r.Use(AdminOnlyMiddleware)
|
||||||
|
|
||||||
|
|||||||
@@ -108,3 +108,7 @@ function applyCatalogSearch() {
|
|||||||
function currentBoardSlug() {
|
function currentBoardSlug() {
|
||||||
return window.location.pathname.split("/")[1] || "";
|
return window.location.pathname.split("/")[1] || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCurrentDateISOString() {
|
||||||
|
return (new Date()).toISOString().slice(0, 16)
|
||||||
|
}
|
||||||
|
|||||||
@@ -48,7 +48,11 @@ templ PostAdminDialog(post database.Post) {
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span>Days: </span>
|
<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>
|
</div>
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
|
|||||||
Reference in New Issue
Block a user