Skip to content

Commit cb0fd6e

Browse files
committed
refac
1 parent e51b661 commit cb0fd6e

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

src/lib/components/chat/FileNav/FilePreview.svelte

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@
103103
$: isNotebook = getExt(selectedFile) === 'ipynb';
104104
$: isCode = isCodeFile(selectedFile);
105105
$: csvDelimiter = getExt(selectedFile) === 'tsv' ? '\t' : ',';
106+
107+
// For HTML files on system terminals (proxy URL), use path-based serving
108+
// so the iframe can resolve relative CSS/JS/image references via cookie auth.
109+
$: serveUrl =
110+
isHtml && selectedFile && baseUrl && baseUrl.includes('/api/v1/terminals/')
111+
? `${baseUrl}/files/serve/${selectedFile.replace(/^\//, '')}`
112+
: null;
106113
$: renderedHtml =
107114
isMarkdown && fileContent
108115
? DOMPurify.sanitize(marked.parse(fileContent, { async: false }) as string)
@@ -386,7 +393,19 @@
386393
{/if}
387394
</div>
388395
{:else if fileContent !== null}
389-
{#if isHtml && !showRaw}
396+
{#if isHtml && !showRaw && serveUrl}
397+
{#if overlay}
398+
<div class="absolute top-0 left-0 right-0 bottom-0 z-10"></div>
399+
{/if}
400+
<iframe
401+
src={serveUrl}
402+
sandbox="allow-scripts allow-same-origin allow-downloads{($settings?.iframeSandboxAllowForms ?? false)
403+
? ' allow-forms'
404+
: ''}"
405+
class="w-full h-full border-none bg-white"
406+
title="HTML Preview"
407+
/>
408+
{:else if isHtml && !showRaw}
390409
{#if overlay}
391410
<div class="absolute top-0 left-0 right-0 bottom-0 z-10"></div>
392411
{/if}

0 commit comments

Comments
 (0)