- 新增 MongoDB 存储层实现英雄、预设和版本数据的持久化 - 新增 push-meta 和 migrate-to-mongo 脚本支持数据同步迁移 - 支持开发版和线上设计版双模式运行 - 新增版本闸门机制,线上设计版落后时进入只读模式 - 优化前端 API 配置适配不同部署环境 - 新增线上设计版静态资源托管和路由回退
36 lines
1.4 KiB
JavaScript
36 lines
1.4 KiB
JavaScript
/**
|
|
* 一次性迁移:把本地 data/heroes.json、data/templates.json 导入线上 MongoDB
|
|
* 用法:配置 MONGO_URL 后执行 node scripts/migrate-to-mongo.js
|
|
* 已在库中的数据会按 uuid 幂等覆盖,可重复执行。
|
|
*/
|
|
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
import url from 'node:url'
|
|
import { saveHeroes, saveTemplates, getHeroes } from '../db.js'
|
|
|
|
const __dirname = path.dirname(url.fileURLToPath(import.meta.url))
|
|
const DATA_DIR = path.join(__dirname, '..', 'data')
|
|
|
|
const readJson = (file, fallback) => {
|
|
const p = path.join(DATA_DIR, file)
|
|
return fs.existsSync(p) ? JSON.parse(fs.readFileSync(p, 'utf8')) : fallback
|
|
}
|
|
|
|
const heroes = readJson('heroes.json', { heroes: [] }).heroes || []
|
|
const tpl = readJson('templates.json', { triggerPresets: [], fieldPresets: [] })
|
|
|
|
if (heroes.length) {
|
|
await saveHeroes(heroes)
|
|
console.log(`[migrate] heroes 导入 ${heroes.length} 条`)
|
|
} else {
|
|
console.log('[migrate] 无本地 heroes.json 或为空,跳过英雄导入')
|
|
}
|
|
if ((tpl.triggerPresets?.length || 0) + (tpl.fieldPresets?.length || 0) > 0) {
|
|
await saveTemplates(tpl.triggerPresets || [], tpl.fieldPresets || [])
|
|
console.log(`[migrate] templates 导入 trigger=${tpl.triggerPresets?.length || 0} field=${tpl.fieldPresets?.length || 0}`)
|
|
} else {
|
|
console.log('[migrate] 无本地 templates.json 或为空,跳过预设导入')
|
|
}
|
|
console.log(`[migrate] 库中现有英雄 ${(await getHeroes()).length} 条`)
|
|
process.exit(0)
|