first successful export

This commit is contained in:
2026-02-25 00:27:36 -08:00
parent b70ea7e877
commit 68ccc2f4fc
14 changed files with 163 additions and 207 deletions

View File

@@ -1,18 +1,13 @@
package handlers
import (
"context"
"encoding/json"
"io"
"net/http"
"path/filepath"
"aroll/store"
)
// UploadHandler reads the video into memory and stores it in Redis under a
// random key. The key is returned to the frontend as "filename".
// Nothing is written to disk — the file lives only in Redis with a TTL.
func UploadHandler(st *store.Store) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
@@ -21,10 +16,11 @@ func UploadHandler(st *store.Store) http.HandlerFunc {
}
r.Body = http.MaxBytesReader(w, r.Body, 4<<30)
if err := r.ParseMultipartForm(64 << 20); err != nil {
if err := r.ParseMultipartForm(32 << 20); err != nil {
http.Error(w, "parse form: "+err.Error(), http.StatusBadRequest)
return
}
defer r.MultipartForm.RemoveAll()
file, header, err := r.FormFile("video")
if err != nil {
@@ -33,22 +29,14 @@ func UploadHandler(st *store.Store) http.HandlerFunc {
}
defer file.Close()
data, err := io.ReadAll(file)
if err != nil {
http.Error(w, "read file: "+err.Error(), http.StatusInternalServerError)
return
}
ext := filepath.Ext(header.Filename)
if ext == "" {
ext = ".mp4"
}
// Key format: "video-<id><ext>" e.g. "video-a3f9...2b.mp4"
key := "video-" + store.NewID() + ext
if err := st.Set(context.Background(), key, data); err != nil {
http.Error(w, "store: "+err.Error(), http.StatusInternalServerError)
key, err := st.Save(file, ext)
if err != nil {
http.Error(w, "save: "+err.Error(), http.StatusInternalServerError)
return
}