From c814af11450d880ea4b6ce634dfde099b74664ca Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Mar 2026 07:48:44 +0000 Subject: [PATCH] fix(ui): preview modal falls back to original version when processed unavailable Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> --- frontend/templates/files.html | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/frontend/templates/files.html b/frontend/templates/files.html index a6e9c2f1..b9b57225 100644 --- a/frontend/templates/files.html +++ b/frontend/templates/files.html @@ -815,18 +815,26 @@ overlay.classList.add('active'); document.body.style.overflow = 'hidden'; - const previewUrl = `/api/files/${fileId}/preview?version=processed`; - footer.innerHTML = ` Full view` + ` Download`; + // Try "processed" first; fall back to "original" on 404 + _pmLoadPreview(body, fileId, mime, filename, 'processed'); + } + + function _pmLoadPreview(body, fileId, mime, filename, version) { + const previewUrl = `/api/files/${fileId}/preview?version=${version}`; if (mime && mime.startsWith('image/')) { _pmRenderImage(body, previewUrl, filename); } else if (mime && mime.startsWith('text/')) { - _pmRenderText(body, previewUrl); + _pmRenderText(body, previewUrl, function() { + if (version === 'processed') _pmLoadPreview(body, fileId, mime, filename, 'original'); + }); } else { - _pmRenderPdf(body, previewUrl); + _pmRenderPdf(body, previewUrl, function() { + if (version === 'processed') _pmLoadPreview(body, fileId, mime, filename, 'original'); + }); } } @@ -838,7 +846,7 @@ } // PDF rendering inside preview modal - function _pmRenderPdf(body, url) { + function _pmRenderPdf(body, url, onError) { body.innerHTML = '
' + '' + @@ -853,6 +861,7 @@ _pmPdf.page = 1; _pmPdfRender(); }).catch(function() { + if (onError) { onError(); return; } document.getElementById('pm-canvas-wrap').innerHTML = '

Failed to load PDF

'; }); } @@ -929,7 +938,7 @@ } // Text rendering inside preview modal - function _pmRenderText(body, url) { + function _pmRenderText(body, url, onError) { body.innerHTML = '
Loading…
'; fetch(url) .then(function(r) { if (!r.ok) throw new Error('HTTP ' + r.status); return r.text(); }) @@ -949,6 +958,7 @@ } }) .catch(function() { + if (onError) { onError(); return; } var c = document.getElementById('pm-text-content'); if (c) c.innerHTML = '
Failed to load file
'; });