feat: add screenshots

This commit is contained in:
2026-04-21 20:27:16 +07:00
parent ba676c2924
commit 0b9c9638b1
20 changed files with 1472 additions and 2690 deletions
+21
View File
@@ -1,5 +1,6 @@
const fs = require('fs');
const path = require('path');
const { execFile } = require('child_process');
module.exports = {
server: {
@@ -17,6 +18,17 @@ module.exports = {
notify: false,
ui: false,
middleware: [
{
route: "/",
handle: function (req, res, next) {
if (req.url === '/' || req.url === '') {
res.writeHead(302, { 'Location': '/tasks/index.html' });
res.end();
return;
}
next();
}
},
{
route: "/api/save-edits",
handle: function (req, res, next) {
@@ -56,6 +68,15 @@ module.exports = {
const diff = computeDiff(oldData, data, docId);
fs.writeFileSync(diffPath, JSON.stringify(diff, null, 2));
// Run generate.mjs → output.html + screenshots (async, don't block response)
const generateScript = path.join(__dirname, 'tasks', taskType, 'scripts', 'generate.mjs');
if (fs.existsSync(generateScript)) {
execFile('node', [generateScript, docId], { timeout: 60000 }, (err, stdout, stderr) => {
if (err) console.error(`[generate] ${taskType}/${docId} failed:`, stderr || err.message);
else console.log(`[generate] ${stdout.trim()}`);
});
}
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ ok: true, path: dataPath }));
} catch (e) {