Replace server-folder docx import with direct file picker

The old import scanned a hardcoded Seafile CloudStorage path that only
worked on one specific machine. Replaced with a standard <input type=file>
browser picker that reads the .docx as base64 and uploads it directly, so
the feature works everywhere. Server endpoint now accepts either a base64
payload or the legacy path. Also fixed a crash where resetImportSection()
still referenced the removed select element, which was breaking the item
editor for all item types.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
nmemmertandClaude Sonnet 4.6 committed 2026-07-29 17:15:23 -04:00
1 parent de598496bc
commit b048f51d46
3 files changed
+33 -40

No files matched your search

+13 -9
View File
@@ -1538,18 +1538,22 @@ Respond with ONLY a JSON object in exactly this shape, nothing else, no markdown
};
app.post('/api/admin/import-docx', requirePin, async (req, res) => {
const { path: relPath, mode } = req.body;
if (!relPath || !TEXT_SCAN_PROMPTS[mode]) {
return res.status(400).json({ error: 'path and mode (lesson or quiz) required' });
}
const fullPath = join(HOMESCHOOL_DIR, relPath);
if (!fullPath.startsWith(HOMESCHOOL_DIR)) {
return res.status(403).json({ error: 'Access denied' });
const { path: relPath, base64: b64, mode } = req.body;
if (!TEXT_SCAN_PROMPTS[mode] || (!relPath && !b64)) {
return res.status(400).json({ error: 'mode and either path or base64 required' });
}
let buffer;
try { buffer = await readFile(fullPath); }
catch (err) { return res.status(404).json({ error: `Could not read file: ${err.message}` }); }
if (b64) {
buffer = Buffer.from(b64, 'base64');
} else {
const fullPath = join(HOMESCHOOL_DIR, relPath);
if (!fullPath.startsWith(HOMESCHOOL_DIR)) {
return res.status(403).json({ error: 'Access denied' });
}
try { buffer = await readFile(fullPath); }
catch (err) { return res.status(404).json({ error: `Could not read file: ${err.message}` }); }
}
let docText;
try {