From 8bd2b34103d29b45bc8975095f9fa57615d8bbbb Mon Sep 17 00:00:00 2001 From: cottongin Date: Tue, 22 Sep 2026 14:36:33 -0400 Subject: [PATCH] feat: auto-use cached HQ video file without upgrade prompt Co-authored-by: Cursor --- src/lib/stores/videoSession.svelte.ts | 78 ++++++++++++++------------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/src/lib/stores/videoSession.svelte.ts b/src/lib/stores/videoSession.svelte.ts index 66be586..e1c6fc2 100644 --- a/src/lib/stores/videoSession.svelte.ts +++ b/src/lib/stores/videoSession.svelte.ts @@ -262,6 +262,22 @@ export async function beginDownload() { session.processingStep = 'downloading'; + // --- Check export (HQ) cache first --- + const exportCached = await checkCachedDownload(session.title, 'export').catch(() => null); + if (exportCached) { + // HQ file already on disk — use it directly, skip preview entirely + session.exportFilePath = exportCached; + session.exportProgress = 1.0; + session.exportStatus = 'complete'; + session.previewFilePath = exportCached; + session.previewProgress = 1.0; + session.previewStatus = 'complete'; + session.activeVideoPath = exportCached; + // No upgrade toast — we're already at best quality + triggerPostDownloadProcessing(exportCached); + return; + } + // --- Preview download (low-res, fast) --- const previewCached = await checkCachedDownload(session.title, 'preview').catch(() => null); if (previewCached) { @@ -305,45 +321,35 @@ export async function beginDownload() { } // --- Export download (best quality, background) --- - const exportCached = await checkCachedDownload(session.title, 'export').catch(() => null); - if (exportCached) { - session.exportFilePath = exportCached; - session.exportProgress = 1.0; - session.exportStatus = 'complete'; - if ((session.processingStep as ProcessingStep) === 'done') { - session.showUpgradeToast = true; - } - } else { - session.exportStatus = 'downloading'; - session.exportProgress = 0; - session.exportFilePath = null; + // Only start if not already cached (we handled cached case above with early return) + session.exportStatus = 'downloading'; + session.exportProgress = 0; + session.exportFilePath = null; - // Fire-and-forget — runs in background - runDownload( - session.url, - EXPORT_FORMAT, - 'export', - (pct) => { session.exportProgress = pct; }, - (path) => { session.exportFilePath = path; }, - (success, path) => { - if (success) { - session.exportProgress = 1.0; - session.exportFilePath = path; - session.exportStatus = 'complete'; - if ((session.processingStep as ProcessingStep) === 'done') { - session.showUpgradeToast = true; - } - } else { - session.exportStatus = 'failed'; + runDownload( + session.url, + EXPORT_FORMAT, + 'export', + (pct) => { session.exportProgress = pct; }, + (path) => { session.exportFilePath = path; }, + (success, path) => { + if (success) { + session.exportProgress = 1.0; + session.exportFilePath = path; + session.exportStatus = 'complete'; + if ((session.processingStep as ProcessingStep) === 'done') { + session.showUpgradeToast = true; } - }, - (message) => { + } else { session.exportStatus = 'failed'; - console.error('Export download error:', message); } - ).catch((e) => { + }, + (message) => { session.exportStatus = 'failed'; - console.error('Export download failed:', e); - }); - } + console.error('Export download error:', message); + } + ).catch((e) => { + session.exportStatus = 'failed'; + console.error('Export download failed:', e); + }); }