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
43 lines
923 B
Go
43 lines
923 B
Go
package static
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"embed"
|
|
"encoding/hex"
|
|
"net/http"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
//go:embed css/* js/* fonts/*
|
|
var staticFS embed.FS
|
|
|
|
// Version is set via -ldflags in production
|
|
var Version string
|
|
|
|
func init() {
|
|
if Version == "" {
|
|
h := sha256.Sum256([]byte(time.Now().String()))
|
|
Version = hex.EncodeToString(h[:4])
|
|
}
|
|
}
|
|
|
|
func VersionedPath(path string) string {
|
|
return "/static/" + Version + "/" + path
|
|
}
|
|
|
|
func Handler() http.Handler {
|
|
fileServer := http.FileServer(http.FS(staticFS))
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
// Strip version prefix: /static/{version}/file.css -> /file.css
|
|
path := r.URL.Path
|
|
path = strings.TrimPrefix(path, "/static/")
|
|
if idx := strings.Index(path, "/"); idx != -1 {
|
|
path = path[idx:]
|
|
}
|
|
r.URL.Path = path
|
|
|
|
w.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
|
|
fileServer.ServeHTTP(w, r)
|
|
})
|
|
}
|