Render document content inline instead of in iframe
Replace the <iframe> with an inline <div> containing the mammoth HTML. Content now flows full-width with the page instead of being cramped in a fixed-height scrolling box. Download link still available below. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
be9d58e972
commit
2384fc9f7d
2 files changed
+8
-14
No files matched your search
+2
-2
@@ -620,8 +620,8 @@ $('#import-go-btn').addEventListener('click', async () => {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: { base64, originalName: file.name },
|
body: { base64, originalName: file.name },
|
||||||
});
|
});
|
||||||
const embed = result.htmlUrl
|
const embed = result.htmlBody
|
||||||
? `<details><summary>📄 ${result.originalName}</summary><iframe src="${result.htmlUrl}" style="width:100%;height:600px;border:1px solid #ccc;border-radius:4px;margin-top:.5em;"></iframe><p><a href="${result.url}" download="${result.originalName}">⬇️ Download ${result.originalName}</a></p></details>`
|
? `<details><summary>📄 ${result.originalName}</summary><div style="border:1px solid #ccc;border-radius:4px;padding:1em;margin-top:.5em;">${result.htmlBody}</div><p><a href="${result.url}" download="${result.originalName}">⬇️ Download ${result.originalName}</a></p></details>`
|
||||||
: `<a href="${result.url}" target="_blank">📄 ${result.originalName}</a>`;
|
: `<a href="${result.url}" target="_blank">📄 ${result.originalName}</a>`;
|
||||||
if (type === 'assignment') {
|
if (type === 'assignment') {
|
||||||
const cur = $('#ie-body-assignment').value;
|
const cur = $('#ie-body-assignment').value;
|
||||||
|
|||||||
@@ -1548,22 +1548,16 @@ app.post('/api/admin/upload-attachment', requirePin, async (req, res) => {
|
|||||||
return res.status(500).json({ error: `Could not save file: ${err.message}` });
|
return res.status(500).json({ error: `Could not save file: ${err.message}` });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert to HTML so it can be shown in an iframe
|
// Convert to HTML for inline rendering
|
||||||
let htmlUrl = null;
|
let htmlBody = null;
|
||||||
try {
|
try {
|
||||||
const { value: bodyHtml } = await mammoth.convertToHtml({ buffer });
|
const { value } = await mammoth.convertToHtml({ buffer });
|
||||||
const htmlFilename = `${uuid}.html`;
|
htmlBody = value || null;
|
||||||
const page = `<!doctype html><html><head><meta charset="utf-8">
|
|
||||||
<style>body{font-family:sans-serif;max-width:800px;margin:2rem auto;padding:0 1rem;line-height:1.6}
|
|
||||||
img{max-width:100%}table{border-collapse:collapse;width:100%}td,th{border:1px solid #ccc;padding:.4em .6em}</style>
|
|
||||||
</head><body>${bodyHtml}</body></html>`;
|
|
||||||
await writeFile(join(ATTACHMENTS_DIR, htmlFilename), page);
|
|
||||||
htmlUrl = `/api/attachments/${htmlFilename}`;
|
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
// HTML preview generation failed — download link still works
|
// preview failed — download link still works
|
||||||
}
|
}
|
||||||
|
|
||||||
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 }));
|
app.get('/health', (req, res) => res.json({ ok: true }));
|
||||||
|
|||||||
Reference in new issue
Block a user