INNER CODE UNIT · JavaScript
ensureCapturesDir
figranium/figranium · src/agent/figranite/index.js:346
const ensureCapturesDir = async () => {
const capturesDir = path.join(__dirname, '../../public', 'captures');
// ⚡ Bolt: Use non-blocking directory creation
await fs.promises.mkdir(capturesDir, { recursive: true });
return capturesDir;
};
const captureScreenshot = async (label) => {
const capturesDir = await ensureCapturesDir();
const safeLabel = label ? String(label).replace(/[^a-zA-Z0-9_-]/g, '').slice(0, 24) : '';
const nameSuffix = safeLabel ? `_${safeLabel}` : '';
const screenshotName = `${captureRunId}_agent_${Date.now()}${nameSuffix}.png`;
const screenshotPath = path.join(capturesDir, screenshotName);
await page.screenshot({ path: screenshotPath, fullPage: false });
return `/captures/${screenshotName}`;
};
// ⚡ Bolt: Pre-calculate which actions need {$html} or loop.html to avoid repeated JSON.stringify (O(N) instead of O(N^2))