feat: restore original-video preview for uploads after reload

The live-analysis preview above the logs used a blob URL for uploaded
sources, which dies on page reload — so a recovered upload session showed an
empty preview (YouTube-URL jobs were fine, their URL persists).

- GET /api/source/{job_id} streams the job's original upload (FileResponse,
  unauthenticated like /videos, UUID job_id is the capability).
- ProcessingAnimation: new 'server' media type -> <video src> from the backend.
- Session save persists uploads as { type:'server', payload:/api/source/id }
  instead of null, so the recovered preview plays the real source.
This commit is contained in:
juancarlos.cavero 2026-07-17 21:57:37 +02:00
parent ff38a9d7ee
commit 97378ab102
3 changed files with 30 additions and 1 deletions

17
app.py
View file

@ -818,6 +818,23 @@ async def get_status(job_id: str, request: Request):
} }
@app.get("/api/source/{job_id}")
async def get_source_video(job_id: str):
"""Stream a job's original source video for the live-analysis preview.
Uploaded sources are blob URLs in the browser and don't survive a reload,
so the recovered session points the preview here instead. Unauthenticated
like the /videos mount — the UUID job_id is the capability.
"""
matches = [
f for f in glob.glob(os.path.join(UPLOAD_DIR, f"{job_id}_*"))
if not os.path.basename(f).startswith("thumb_")
]
if not matches:
raise HTTPException(status_code=404, detail="Source not found")
return FileResponse(matches[0], media_type="video/mp4")
@app.get("/api/jobs/{job_id}/download-all") @app.get("/api/jobs/{job_id}/download-all")
async def download_all_clips(job_id: str, request: Request): async def download_all_clips(job_id: str, request: Request):
"""Bundle the current version of every clip of a job into one ZIP.""" """Bundle the current version of every clip of a job into one ZIP."""

View file

@ -312,11 +312,17 @@ function App() {
return; return;
} }
try { try {
// URL (YouTube) media serializes as-is. Uploaded 'file' media is a blob
// that can't be persisted, so point the recovered preview at the source
// served by the backend instead of dropping it.
let persistMedia = null;
if (processingMedia?.type === 'url') persistMedia = processingMedia;
else if (processingMedia && jobId) persistMedia = { type: 'server', payload: `/api/source/${jobId}` };
const sessionData = { const sessionData = {
jobId, jobId,
status, status,
results, results,
processingMedia: processingMedia?.type === 'url' ? processingMedia : null, processingMedia: persistMedia,
activeTab, activeTab,
timestamp: Date.now() timestamp: Date.now()
}; };

View file

@ -1,5 +1,6 @@
import React, { useEffect, useState, useRef } from 'react'; import React, { useEffect, useState, useRef } from 'react';
import { Scan, Scissors, Activity, Radio, CheckCircle } from 'lucide-react'; import { Scan, Scissors, Activity, Radio, CheckCircle } from 'lucide-react';
import { getApiUrl } from '../config';
const ProcessingAnimation = ({ media, isComplete, syncedTime, isSyncedPlaying, syncTrigger }) => { const ProcessingAnimation = ({ media, isComplete, syncedTime, isSyncedPlaying, syncTrigger }) => {
const [videoSrc, setVideoSrc] = useState(null); const [videoSrc, setVideoSrc] = useState(null);
@ -12,8 +13,13 @@ const ProcessingAnimation = ({ media, isComplete, syncedTime, isSyncedPlaying, s
if (media.type === 'file') { if (media.type === 'file') {
const url = URL.createObjectURL(media.payload); const url = URL.createObjectURL(media.payload);
setIsYouTube(false);
setVideoSrc(url); setVideoSrc(url);
return () => URL.revokeObjectURL(url); return () => URL.revokeObjectURL(url);
} else if (media.type === 'server') {
// Uploaded source served from the backend (survives a page reload).
setIsYouTube(false);
setVideoSrc(getApiUrl(media.payload));
} else if (media.type === 'url') { } else if (media.type === 'url') {
setIsYouTube(true); setIsYouTube(true);
const videoId = getYouTubeId(media.payload); const videoId = getYouTubeId(media.payload);