refactor(media): replace hand-rolled SigV4 with maintained minio-go SDK; add /admin/media/upload endpoint

This commit is contained in:
sam
2026-09-10 07:12:35 +10:00
parent df4a19933c
commit 5acddaa605
5 changed files with 166 additions and 157 deletions

View File

@@ -37,25 +37,16 @@ func main() {
log.Printf("loaded %d articles across %d subjects", len(c.Articles), len(c.Subjects))
s := NewSite(c)
// media proxy config (Garage S3)
s.Media = &S3MediaClient{
Endpoint: os.Getenv("KONTRA_S3_ENDPOINT"),
Bucket: os.Getenv("KONTRA_S3_BUCKET"),
Key: os.Getenv("KONTRA_S3_KEY"),
Secret: os.Getenv("KONTRA_S3_SECRET"),
Client: http.Client{},
}
if s.Media.Endpoint == "" {
s.Media.Endpoint = "http://127.0.0.1:3900"
}
if s.Media.Bucket == "" {
s.Media.Bucket = "kontra-day"
}
// media (Garage S3 via minio-go SDK)
s.Media = NewMediaClient()
// Routes — register specific paths BEFORE the catch-all.
http.HandleFunc("/media/{path...}", func(w http.ResponseWriter, r *http.Request) {
s.media(w, r, r.PathValue("path"))
})
http.HandleFunc("/admin/media/upload", func(w http.ResponseWriter, r *http.Request) {
s.mediaUpload(w, r)
})
http.HandleFunc("/subjects/{slug}", func(w http.ResponseWriter, r *http.Request) {
s.subject(w, r, r.PathValue("slug"))
})