diff --git a/app.py b/app.py index 1d67be5..ef38e92 100644 --- a/app.py +++ b/app.py @@ -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") async def download_all_clips(job_id: str, request: Request): """Bundle the current version of every clip of a job into one ZIP.""" diff --git a/dashboard/src/App.jsx b/dashboard/src/App.jsx index 5dda430..7558fb8 100644 --- a/dashboard/src/App.jsx +++ b/dashboard/src/App.jsx @@ -312,11 +312,17 @@ function App() { return; } 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 = { jobId, status, results, - processingMedia: processingMedia?.type === 'url' ? processingMedia : null, + processingMedia: persistMedia, activeTab, timestamp: Date.now() }; diff --git a/dashboard/src/components/ProcessingAnimation.jsx b/dashboard/src/components/ProcessingAnimation.jsx index d1269cf..bc1eee2 100644 --- a/dashboard/src/components/ProcessingAnimation.jsx +++ b/dashboard/src/components/ProcessingAnimation.jsx @@ -1,5 +1,6 @@ import React, { useEffect, useState, useRef } from 'react'; import { Scan, Scissors, Activity, Radio, CheckCircle } from 'lucide-react'; +import { getApiUrl } from '../config'; const ProcessingAnimation = ({ media, isComplete, syncedTime, isSyncedPlaying, syncTrigger }) => { const [videoSrc, setVideoSrc] = useState(null); @@ -12,8 +13,13 @@ const ProcessingAnimation = ({ media, isComplete, syncedTime, isSyncedPlaying, s if (media.type === 'file') { const url = URL.createObjectURL(media.payload); + setIsYouTube(false); setVideoSrc(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') { setIsYouTube(true); const videoId = getYouTubeId(media.payload);