diff --git a/public/admin.js b/public/admin.js
index dab6668..031d315 100644
--- a/public/admin.js
+++ b/public/admin.js
@@ -620,8 +620,8 @@ $('#import-go-btn').addEventListener('click', async () => {
method: 'POST',
body: { base64, originalName: file.name },
});
- const embed = result.htmlBody
- ? `📄 ${result.originalName}
${result.htmlBody}
⬇️ Download ${result.originalName}
`
+ const embed = result.htmlUrl
+ ? `📄 ${result.originalName}
⬇️ Download ${result.originalName}
`
: `📄 ${result.originalName}`;
if (type === 'assignment') {
const cur = $('#ie-body-assignment').value;
diff --git a/server.js b/server.js
index 1918334..592c716 100644
--- a/server.js
+++ b/server.js
@@ -1548,16 +1548,23 @@ 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 inline rendering
- let htmlBody = null;
+ // Convert to HTML for the iframe viewer
+ let htmlUrl = null;
try {
- const { value } = await mammoth.convertToHtml({ buffer });
- htmlBody = value || null;
+ 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}`;
} catch (_) {
// preview failed — download link still works
}
- return res.json({ url: `/api/attachments/${filename}`, htmlBody, originalName });
+ return res.json({ url: `/api/attachments/${filename}`, htmlUrl, originalName });
});
app.get('/health', (req, res) => res.json({ ok: true }));