feat(thought-lab): 新增万花筒与闵可夫斯基画板两个思想实验室

新增两个独立思想实验室:
1. 万花筒模拟器:支持可调参数物理万花筒效果,配置方案SQLite持久化
2. 闵可夫斯基画板:支持世界线绘制、洛伦兹变换、光锥因果判定
同时添加自动绑定实验室后端的逻辑,以及配套的单元测试与前端页面
This commit is contained in:
yangxiangyuan
2026-08-06 17:41:43 +08:00
parent ea379116cc
commit 876a3b8768
17 changed files with 9979 additions and 0 deletions
+22
View File
@@ -144,6 +144,28 @@ const bindRoutes = (app) => {
// 4) 其余 /api/thought_lab 接口:默认导航鉴权
app.use('/api/thought_lab', navAuthApi)
// 5) lab 后端自动绑定:labs/<lab_id>/index.js 若导出 bindRoutes 则独立注册
// (注册在 API 守卫之后,自动继承导航鉴权;各 lab 互不干扰)
bindLabBackends(app)
}
const bindLabBackends = (app) => {
try {
if (!fs.existsSync(LABS_DIR)) return
const dirs = fs.readdirSync(LABS_DIR, { withFileTypes: true })
for (const d of dirs) {
if (!d.isDirectory()) continue
const entry = path.join(LABS_DIR, d.name, 'index.js')
if (!fs.existsSync(entry)) continue
try {
const mod = require(entry)
if (mod && typeof mod.bindRoutes === 'function') mod.bindRoutes(app)
} catch (e) {
try { console.error(`[thought_lab] 绑定 lab 后端失败: ${d.name} ${String(e.message || e)}`) } catch {}
}
}
} catch {}
}
module.exports = { bindRoutes, listLabs, loadLabConfig }