From 4b41f7d5e178ff8ba0d6d3764b1b928378d0d73e Mon Sep 17 00:00:00 2001 From: mike Date: Wed, 4 Nov 2026 09:48:25 +0800 Subject: [PATCH] Update App.jsx via upload script - 2026-11-04 09:48:16 --- App.jsx | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/App.jsx b/App.jsx index e37144c..2deba01 100644 --- a/App.jsx +++ b/App.jsx @@ -7422,6 +7422,37 @@ function replaceHtmlVisual(html, idx, img) { } return full ? (doctype ? doctype + '\n' : '') + doc.documentElement.outerHTML : doc.body.innerHTML; } +// 处理好的图片存成模板目录下的文件(uploads/<模板id>/),HTML 里只写地址,模板数据不会因为图片变大 +async function uploadHtmlImage(tplId, img) { + const blob = await (await fetch(img.src)).blob(); + const ext = blob.type === 'image/webp' ? '.webp' : blob.type === 'image/png' ? '.png' : '.jpg'; + const res = await uploadFile(tplId, new File([blob], 'html' + ext, { type: blob.type })); + return { ...img, src: `/uploads/${tplId}/${res.fileName}` }; +} +// 预览用:iframe 是隔离的(拿不到登录状态,读不了 /uploads/),先把图片读出来、临时换成内嵌数据再显示;只用于预览,不保存 +const previewImgCache = new Map(); +async function inlineForPreview(html) { + const src = String(html || ''); + const urls = [...new Set(src.match(/\/uploads\/[A-Za-z0-9_-]+\/[A-Za-z0-9_.-]+/g) || [])]; + let out = src; + for (const u of urls) { + if (!previewImgCache.has(u)) previewImgCache.set(u, fetch(u).then(r => (r.ok ? r.blob() : null)).then(b => (b ? new Promise(ok => { const fr = new FileReader(); fr.onload = () => ok(fr.result); fr.readAsDataURL(b); }) : null)).catch(() => null)); + const d = await previewImgCache.get(u); + if (d) out = out.split(u).join(d); + } + return out; +} +// 预览 iframe:内容异步准备好(图片换成内嵌数据)再显示 +function HtmlPreviewFrame({ html, extra, picking }) { + const [doc, setDoc] = useState(''); + useEffect(() => { + let alive = true; + const t = setTimeout(() => { inlineForPreview(html).then(d => { if (alive) setDoc(d + (extra || '')); }); }, 150); + return () => { alive = false; clearTimeout(t); }; + }, [html, extra]); + return