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,11 +1,8 @@
package handlers
import (
"context"
"encoding/json"
"net/http"
"os"
"path/filepath"
"aroll/store"
"aroll/transcode"
@@ -19,8 +16,6 @@ type analyzeRequest struct {
Padding float64 `json:"padding"`
}
// AnalyzeHandler fetches the video bytes from Redis, writes them to a short-lived
// temp file for FFmpeg, runs silence detection, then deletes the temp file.
func AnalyzeHandler(st *store.Store, hub *ws.Hub) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
@@ -34,33 +29,15 @@ func AnalyzeHandler(st *store.Store, hub *ws.Hub) http.HandlerFunc {
return
}
data, err := st.Get(context.Background(), req.Filename)
if err != nil {
http.Error(w, "file not found in store (may have expired)", http.StatusNotFound)
path, ok := st.Path(req.Filename)
if !ok {
http.Error(w, "file not found", http.StatusNotFound)
return
}
ext := filepath.Ext(req.Filename)
go func() {
// Write to a temp file — FFmpeg needs a file path, not a byte slice.
// This file exists only for the duration of the FFmpeg scan.
tmp, err := os.CreateTemp("", "aroll-analyze-*"+ext)
if err != nil {
broadcastError(hub, "create temp: "+err.Error())
return
}
defer os.Remove(tmp.Name())
if _, err := tmp.Write(data); err != nil {
tmp.Close()
broadcastError(hub, "write temp: "+err.Error())
return
}
tmp.Close()
_, err = transcode.DetectSpeechSegments(
tmp.Name(),
_, err := transcode.DetectSpeechSegments(
path,
req.NoiseDb,
req.MinSilence,
req.Padding,