first commit

This commit is contained in:
2026-02-17 17:15:39 -08:00
parent 1bf9c29f09
commit b70ea7e877
25 changed files with 4145 additions and 0 deletions

40
handlers/download.go Normal file
View File

@@ -0,0 +1,40 @@
package handlers
import (
"context"
"net/http"
"strconv"
"strings"
"aroll/store"
)
// DownloadHandler fetches the exported video from Redis, streams it to the
// browser, then immediately deletes the key. One download per export.
func DownloadHandler(st *store.Store) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
key := strings.TrimPrefix(r.URL.Path, "/")
// Only serve keys we created in ExportHandler
if !strings.HasPrefix(key, "output-") {
http.NotFound(w, r)
return
}
ctx := context.Background()
data, err := st.Get(ctx, key)
if err != nil {
http.Error(w, "file not found or already downloaded", http.StatusNotFound)
return
}
// Delete from Redis now — one download only
defer st.Delete(ctx, key)
w.Header().Set("Content-Type", "video/mp4")
w.Header().Set("Content-Disposition", `attachment; filename="aroll-cut.mp4"`)
w.Header().Set("Content-Length", strconv.Itoa(len(data)))
w.Write(data)
}
}