// 只读分析:递归抓取 NapCat WebUI 所有前端 chunk(含懒加载),提取后端路由。 // 不发送写请求,不修改任何配置。 const BASE = (process.env.NAPCAT_WEBUI_URL || 'http://192.168.5.32:6099').replace(/\/$/, ''); const seen = new Set(); const queue = []; const routes = new Map(); function collect(src, from) { for (const m of src.matchAll(/\.(post|get|put|delete)\(\s*"([^"]{2,70})"/g)) { const key = `${m[1].toUpperCase()} ${m[2]}`; if (!routes.has(key)) routes.set(key, from); } for (const m of src.matchAll(/assets\/[A-Za-z0-9_.-]+\.js/g)) queue.push(m[0]); } async function fetchText(url) { try { return await fetch(url, { signal: AbortSignal.timeout(20000) }).then(r => r.ok ? r.text() : ''); } catch { return ''; } } const entry = await fetchText(`${BASE}/webui/`); collect(entry, 'index.html'); let round = 0; while (queue.length && round < 400) { const c = queue.shift(); if (seen.has(c)) continue; seen.add(c); round++; const src = await fetchText(`${BASE}/webui/${c}`); if (src) collect(src, c.split('/').pop()); } console.log(`扫描 ${seen.size} 个 chunk`); console.log(`\n=== ${routes.size} 个路由 ===`); [...routes.entries()].sort().forEach(([k, v]) => console.log(` ${k} <- ${v}`));