fix: editor
This commit is contained in:
+15
-1
@@ -2,6 +2,9 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { execFile } = require('child_process');
|
||||
|
||||
// Deduplicate rapid-fire save requests (browser-sync may relay POSTs twice)
|
||||
const _lastSave = {};
|
||||
|
||||
module.exports = {
|
||||
server: {
|
||||
baseDir: "."
|
||||
@@ -10,7 +13,7 @@ module.exports = {
|
||||
"tasks/index.html",
|
||||
"tasks/*/index.html",
|
||||
"tasks/*/docs/*.template.html",
|
||||
"tasks/*/docs/*.output.html",
|
||||
// output.html excluded: generated by save flow, reload would wipe editor state
|
||||
"tasks/*/editor.html",
|
||||
"assets/**/*",
|
||||
"public/**/*"
|
||||
@@ -48,6 +51,17 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
|
||||
// Deduplicate: skip if same docId saved within 500ms
|
||||
const saveKey = `${taskType}/${docId}`;
|
||||
const now = Date.now();
|
||||
if (_lastSave[saveKey] && now - _lastSave[saveKey].time < 500) {
|
||||
console.log(`[save] dedup skip ${saveKey} (${now - _lastSave[saveKey].time}ms since last)`);
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ ok: true, dedup: true }));
|
||||
return;
|
||||
}
|
||||
_lastSave[saveKey] = { time: now, body: body.length };
|
||||
|
||||
const docsDir = path.join(__dirname, 'tasks', taskType, 'docs');
|
||||
const tempDir = path.join(__dirname, 'tasks', taskType, 'temp');
|
||||
fs.mkdirSync(tempDir, { recursive: true });
|
||||
|
||||
Reference in New Issue
Block a user