fix: 优化虫 机制,新增伊朗支援

This commit is contained in:
Daniel
2026-03-06 10:34:52 +08:00
parent 89145a6743
commit 9f2442f2e3
20 changed files with 411 additions and 62 deletions

Binary file not shown.

View File

View File

@@ -310,6 +310,49 @@ function runMigrations(db) {
);
`)
} catch (_) {}
// 生产环境可能未跑 seed 或使用旧 seed补齐 war_map_config 与以色列→黎巴嫩打击线,保证攻击动画显示
try {
let row = db.prepare('SELECT 1 FROM war_map_config WHERE id = 1').get()
if (!row) {
const warMapConfig = {
pincerAxes: [
{ start: [43.6, 37.2], end: [46.27, 38.08], name: 'North Pincer (Tabriz)' },
{ start: [45.0, 35.4], end: [46.99, 35.31], name: 'Central Pincer (Sanandaj)' },
{ start: [45.6, 35.2], end: [47.07, 34.31], name: 'South Pincer (Kermanshah)' },
],
israelLebanonAxis: { start: [35.25, 32.95], end: [35.55, 33.45], name: 'Israel → Lebanon' },
defenseLinePath: [[46.27, 38.08], [46.99, 35.31], [47.07, 34.31]],
}
db.prepare(
'INSERT INTO war_map_config (id, config, updated_at) VALUES (1, ?, datetime(\'now\'))'
).run(JSON.stringify(warMapConfig))
}
// 确保 map_strike_source 有 israel否则打击线无法关联
db.prepare(
'INSERT OR IGNORE INTO map_strike_source (id, name, lng, lat) VALUES (\'israel\', \'以色列\', 34.78, 32.08)'
).run()
const israelLebanonTargets = [
[35.5, 33.86, '贝鲁特南郊指挥所', '2026-02-28T14:00:00.000Z'],
[35.32, 33.34, '利塔尼弹药库', '2026-02-28T14:10:00.000Z'],
[36.2, 34.01, '巴勒贝克后勤枢纽', '2026-02-28T14:20:00.000Z'],
[35.19, 33.27, '提尔海岸阵地', '2026-02-28T14:30:00.000Z'],
[36.38, 34.39, '赫尔梅勒无人机阵地', '2026-02-28T14:40:00.000Z'],
]
const insertStrikeLine = db.prepare(
'INSERT INTO map_strike_line (source_id, target_lng, target_lat, target_name, struck_at) VALUES (?, ?, ?, ?, ?)'
)
const hasStrikeLine = db.prepare(
'SELECT 1 FROM map_strike_line WHERE source_id = ? AND target_lng = ? AND target_lat = ?'
)
for (const [lng, lat, name, struckAt] of israelLebanonTargets) {
if (!hasStrikeLine.get('israel', lng, lat)) {
insertStrikeLine.run('israel', lng, lat, name, struckAt)
}
}
} catch (_) {}
}
async function initDb() {

View File

@@ -79,6 +79,8 @@ function getSituation() {
const trend = db.prepare('SELECT time, value FROM wall_street_trend ORDER BY time').all()
const retaliationCur = db.prepare('SELECT value FROM retaliation_current WHERE id = 1').get()
const retaliationHist = db.prepare('SELECT time, value FROM retaliation_history ORDER BY time').all()
// 反击情绪无记录时给默认 50避免爬虫未写入时前端显示 0
const retaliationValue = retaliationCur?.value ?? 50
const updates = db.prepare('SELECT * FROM situation_update ORDER BY timestamp DESC LIMIT 50').all()
// 数据更新时间:与前端「实时更新」一致,仅在爬虫 notify / 编辑保存时由 index.js 或 routes 更新
const meta = db.prepare('SELECT updated_at FROM situation WHERE id = 1').get()
@@ -157,7 +159,7 @@ function getSituation() {
assets: (assetsIr || []).map(toAsset),
keyLocations: locIr || [],
combatLosses: irLosses,
retaliationSentiment: retaliationCur?.value ?? 0,
retaliationSentiment: retaliationValue,
retaliationSentimentHistory: retaliationHist || [],
},
recentUpdates: (updates || []).map((u) => ({