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 }));