Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bb1b97af3c |
@@ -51,9 +51,12 @@ export function createPreviewHandler({ runtime = process.env.PCB_SESSION_ROOT ||
|
||||
const cache = new Map(), pending = new Map(), captureAfter = new Map();
|
||||
let capturing = false;
|
||||
async function preview(tid, kind) {
|
||||
const task = JSON.parse(await readFile(resolve(runtime, 'tasks', tid, 'state.json'), 'utf8'));
|
||||
// Canonicalize the configured root so OS aliases such as macOS /tmp do
|
||||
// not look like task-owned symlinks to exportedFrame's containment check.
|
||||
const runtimeRoot = await realpath(runtime);
|
||||
const task = JSON.parse(await readFile(resolve(runtimeRoot, 'tasks', tid, 'state.json'), 'utf8'));
|
||||
let frame = null, reason = 'waiting_for_canvas';
|
||||
const savedPath = resolve(runtime, 'web-previews', `${tid}.json`);
|
||||
const savedPath = resolve(runtimeRoot, 'web-previews', `${tid}.json`);
|
||||
if (task.approval && task.eda_session && task.state === 'running' && !capturing && Date.now() >= (captureAfter.get(tid) || 0)) {
|
||||
capturing = true;
|
||||
if (captureAfter.size > 100) captureAfter.delete(captureAfter.keys().next().value);
|
||||
@@ -63,7 +66,7 @@ export function createPreviewHandler({ runtime = process.env.PCB_SESSION_ROOT ||
|
||||
reason = value.reason || '';
|
||||
if (value.available && ['schematic', 'layout', '3d'].includes(value.kind) && /^data:image\/png;base64,/.test(value.image)) {
|
||||
frame = { kind: value.kind, capturedAt: Date.now(), source: 'canvas', image: value.image };
|
||||
await mkdir(resolve(runtime, 'web-previews'), { recursive: true });
|
||||
await mkdir(resolve(runtimeRoot, 'web-previews'), { recursive: true });
|
||||
await writeFile(savedPath + '.tmp', JSON.stringify(frame));
|
||||
await rename(savedPath + '.tmp', savedPath);
|
||||
}
|
||||
@@ -72,7 +75,7 @@ export function createPreviewHandler({ runtime = process.env.PCB_SESSION_ROOT ||
|
||||
} else if (capturing) reason = 'eda_busy';
|
||||
if (!frame) frame = await readFile(savedPath, 'utf8').then(JSON.parse).catch(() => null);
|
||||
if (frame && kind !== 'auto' && frame.kind !== kind) frame = null;
|
||||
const exported = await exportedFrame(resolve(runtime, 'tasks', tid, 'workspace', 'artifacts'), kind).catch(() => null);
|
||||
const exported = await exportedFrame(resolve(runtimeRoot, 'tasks', tid, 'workspace', 'artifacts'), kind).catch(() => null);
|
||||
if (exported && (!frame || exported.capturedAt > frame.capturedAt)) frame = exported;
|
||||
return { taskId: tid, frame, reason, refreshSeconds: 5 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user