fix: 新增态 效果
This commit is contained in:
@@ -191,6 +191,41 @@ router.get('/stats', (req, res) => {
|
||||
}
|
||||
})
|
||||
|
||||
// 战区地图配置:钳形轴线、以黎轴线、防御线路径,供前端 useWarMapData 拉取;新增/修改数据落库
|
||||
router.get('/war-map-config', (req, res) => {
|
||||
try {
|
||||
const row = db.prepare('SELECT config FROM war_map_config WHERE id = 1').get()
|
||||
if (!row || !row.config) {
|
||||
return res.json({})
|
||||
}
|
||||
const data = JSON.parse(row.config)
|
||||
res.json(data)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
res.status(500).json({ error: err.message })
|
||||
}
|
||||
})
|
||||
|
||||
router.put('/war-map-config', requireAdmin, (req, res) => {
|
||||
try {
|
||||
const body = req.body || {}
|
||||
const pincerAxes = Array.isArray(body.pincerAxes) ? body.pincerAxes : null
|
||||
const israelLebanonAxis = body.israelLebanonAxis && typeof body.israelLebanonAxis === 'object' ? body.israelLebanonAxis : null
|
||||
const defenseLinePath = Array.isArray(body.defenseLinePath) ? body.defenseLinePath : null
|
||||
if (!pincerAxes?.length || !israelLebanonAxis || !defenseLinePath?.length) {
|
||||
return res.status(400).json({ error: 'pincerAxes (array), israelLebanonAxis (object), defenseLinePath (array) required' })
|
||||
}
|
||||
const config = JSON.stringify({ pincerAxes, israelLebanonAxis, defenseLinePath })
|
||||
db.prepare(
|
||||
'INSERT INTO war_map_config (id, config, updated_at) VALUES (1, ?, datetime(\'now\')) ON CONFLICT(id) DO UPDATE SET config = excluded.config, updated_at = datetime(\'now\')'
|
||||
).run(config)
|
||||
res.json({ ok: true })
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
res.status(500).json({ error: err.message })
|
||||
}
|
||||
})
|
||||
|
||||
router.get('/events', (req, res) => {
|
||||
try {
|
||||
const s = getSituation()
|
||||
@@ -225,9 +260,13 @@ router.get('/edit/raw', (req, res) => {
|
||||
const summaryUs = db.prepare('SELECT * FROM force_summary WHERE side = ?').get('us')
|
||||
const summaryIr = db.prepare('SELECT * FROM force_summary WHERE side = ?').get('iran')
|
||||
let displayStats = null
|
||||
let animationConfig = null
|
||||
try {
|
||||
displayStats = db.prepare('SELECT override_enabled, viewers, cumulative, share_count, like_count, feedback_count FROM display_stats WHERE id = 1').get()
|
||||
} catch (_) {}
|
||||
try {
|
||||
animationConfig = db.prepare('SELECT strike_cutoff_days FROM animation_config WHERE id = 1').get()
|
||||
} catch (_) {}
|
||||
const realCumulative = db.prepare('SELECT total FROM visitor_count WHERE id = 1').get()?.total ?? 0
|
||||
const realShare = db.prepare('SELECT total FROM share_count WHERE id = 1').get()?.total ?? 0
|
||||
const liveViewers = db.prepare(
|
||||
@@ -251,6 +290,9 @@ router.get('/edit/raw', (req, res) => {
|
||||
likeCount: displayStats?.like_count ?? realLikeCount,
|
||||
feedbackCount: displayStats?.feedback_count ?? realFeedback,
|
||||
},
|
||||
animationConfig: {
|
||||
strikeCutoffDays: animationConfig?.strike_cutoff_days ?? 5,
|
||||
},
|
||||
})
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
@@ -438,4 +480,20 @@ router.put('/edit/display-stats', (req, res) => {
|
||||
}
|
||||
})
|
||||
|
||||
router.put('/edit/animation-config', (req, res) => {
|
||||
try {
|
||||
const body = req.body || {}
|
||||
const v = body.strikeCutoffDays
|
||||
const n = Math.max(1, parseInt(v, 10) || 0)
|
||||
if (!Number.isFinite(n)) return res.status(400).json({ error: 'strikeCutoffDays must be number' })
|
||||
db.prepare('INSERT OR IGNORE INTO animation_config (id, strike_cutoff_days) VALUES (1, 5)').run()
|
||||
db.prepare('UPDATE animation_config SET strike_cutoff_days = ?, updated_at = datetime(\'now\') WHERE id = 1').run(n)
|
||||
broadcastAfterEdit(req)
|
||||
res.json({ ok: true })
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
res.status(400).json({ error: err.message })
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
|
||||
Reference in New Issue
Block a user