From 183bcf0ef2dcb8ea4f3a39c971f1d70128958b77 Mon Sep 17 00:00:00 2001 From: nmemmert <67961292+nmemmert@users.noreply.github.com> Date: Thu, 30 Jul 2026 12:26:55 -0400 Subject: [PATCH] Import .docx content directly into RTE editor as editable HTML Instead of embedding an iframe, mammoth HTML is inserted straight into the contenteditable body so the admin can edit it like any other content. A download link to the original .docx sits above the content. Co-Authored-By: Claude Sonnet 4.6 --- public/admin.js | 16 +++++++--------- server.js | 29 ++++++----------------------- 2 files changed, 13 insertions(+), 32 deletions(-) diff --git a/public/admin.js b/public/admin.js index 8f758f0..25d1b68 100644 --- a/public/admin.js +++ b/public/admin.js @@ -623,15 +623,13 @@ $('#import-go-btn').addEventListener('click', async () => { method: 'POST', body: { base64, originalName: file.name }, }); - const embed = result.htmlUrl - ? `
📄 ${result.originalName}

⬇️ Download ${result.originalName}

` - : `📄 ${result.originalName}`; - if (type === 'assignment') { - $('#ie-body-assignment').innerHTML += embed; - } else { - $('#ie-body-lesson').innerHTML += embed; - } - $('#import-status').textContent = '✅ File uploaded. Document embedded in body.'; + const downloadLink = `

⬇️ ${result.originalName}

`; + const content = result.htmlBody + ? downloadLink + result.htmlBody + : `

📄 ${result.originalName}

`; + const editor = type === 'assignment' ? $('#ie-body-assignment') : $('#ie-body-lesson'); + editor.innerHTML += content; + $('#import-status').textContent = '✅ Imported — content is now editable above.'; } catch (err) { $('#import-status').textContent = `❌ ${err.message}`; } finally { diff --git a/server.js b/server.js index 9f2b190..536dd8f 100644 --- a/server.js +++ b/server.js @@ -1548,33 +1548,16 @@ app.post('/api/admin/upload-attachment', requirePin, async (req, res) => { return res.status(500).json({ error: `Could not save file: ${err.message}` }); } - // Convert to HTML for the iframe viewer - let htmlUrl = null; + // Convert to HTML for inline editing in the RTE + let htmlBody = null; try { - const { value: bodyHtml } = await mammoth.convertToHtml({ buffer }); - const htmlFilename = `${uuid}.html`; - const page = ` - -${bodyHtml}`; - await writeFile(join(ATTACHMENTS_DIR, htmlFilename), page); - htmlUrl = `/api/attachments/${htmlFilename}`; + const { value } = await mammoth.convertToHtml({ buffer }); + htmlBody = value || null; } catch (_) { - // preview failed — download link still works + // conversion failed — download link still available } - return res.json({ url: `/api/attachments/${filename}`, htmlUrl, originalName }); + return res.json({ url: `/api/attachments/${filename}`, htmlBody, originalName }); }); app.get('/health', (req, res) => res.json({ ok: true }));