Pinterest-like app for saving images, videos, quotes, and embeds. Features: - Go backend with PostgreSQL, SSR templates - Console-based admin auth (login/logout via browser console) - Item types: images, videos (ffmpeg transcoding), quotes, embeds - Media stored as BLOBs in PostgreSQL - OpenGraph metadata extraction for links - Embed detection for YouTube, Vimeo, Twitter/X - Masonry grid layout, item detail pages - Tag system with filtering - Refresh metadata endpoint with change warnings - Replace media endpoint for updating item images/videos
27 lines
638 B
Go
27 lines
638 B
Go
package handlers
|
|
|
|
import (
|
|
"database/sql"
|
|
"log/slog"
|
|
"net/http"
|
|
|
|
"git.soup.land/soup/sxgo/ssr"
|
|
)
|
|
|
|
// RequestContext holds dependencies that are injected into every request handler.
|
|
type RequestContext struct {
|
|
DB *sql.DB
|
|
Logger *slog.Logger
|
|
TmplCache *ssr.TmplCache
|
|
IsAdmin bool // true if authenticated as admin
|
|
}
|
|
|
|
// RequireAdmin checks authentication and returns 401 if not admin.
|
|
// Returns true if authenticated, false if 401 was sent.
|
|
func (rc *RequestContext) RequireAdmin(w http.ResponseWriter) bool {
|
|
if !rc.IsAdmin {
|
|
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
|
return false
|
|
}
|
|
return true
|
|
}
|