fix: 修复爬虫问题

This commit is contained in:
Daniel
2026-03-02 17:20:31 +08:00
parent 33e4786cd0
commit 0027074b8b
21 changed files with 523 additions and 16 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -112,6 +112,21 @@ db.exec(`
estimated_strike_count INTEGER NOT NULL DEFAULT 0,
updated_at TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS news_content (
id TEXT PRIMARY KEY,
content_hash TEXT NOT NULL UNIQUE,
title TEXT NOT NULL,
summary TEXT NOT NULL,
url TEXT NOT NULL DEFAULT '',
source TEXT NOT NULL DEFAULT '',
published_at TEXT NOT NULL,
category TEXT NOT NULL DEFAULT 'other',
severity TEXT NOT NULL DEFAULT 'medium',
created_at TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE INDEX IF NOT EXISTS idx_news_content_hash ON news_content(content_hash);
CREATE INDEX IF NOT EXISTS idx_news_content_published ON news_content(published_at DESC);
`)
// 迁移:为已有 key_location 表添加 type、region、status、damage_level 列

View File

@@ -25,6 +25,15 @@ module.exports = {
},
},
},
'/api/news': {
get: {
summary: '资讯内容',
description: '从 news_content 表读取,支持 ?limit=50 分页',
tags: ['资讯'],
parameters: [{ in: 'query', name: 'limit', schema: { type: 'integer', default: 50 } }],
responses: { 200: { description: 'items 数组' } },
},
},
'/api/db/dashboard': {
get: {
summary: '数据库面板',
@@ -130,5 +139,5 @@ module.exports = {
},
},
},
tags: [{ name: '态势' }, { name: '统计' }, { name: '反馈' }, { name: '调试' }, { name: '系统' }],
tags: [{ name: '态势' }, { name: '资讯' }, { name: '统计' }, { name: '反馈' }, { name: '调试' }, { name: '系统' }],
}

View File

@@ -19,6 +19,7 @@ router.get('/db/dashboard', (req, res) => {
'retaliation_current',
'retaliation_history',
'situation_update',
'news_content',
'gdelt_events',
'conflict_stats',
]
@@ -27,6 +28,7 @@ router.get('/db/dashboard', (req, res) => {
feedback: 'created_at DESC',
situation: 'updated_at DESC',
situation_update: 'timestamp DESC',
news_content: 'published_at DESC',
gdelt_events: 'event_time DESC',
wall_street_trend: 'time DESC',
retaliation_history: 'time DESC',
@@ -55,6 +57,17 @@ router.get('/db/dashboard', (req, res) => {
}
})
// 资讯内容(独立表,供后续消费)
router.get('/news', (req, res) => {
try {
const limit = Math.min(parseInt(req.query.limit, 10) || 50, 200)
const rows = db.prepare('SELECT id, title, summary, url, source, published_at, category, severity, created_at FROM news_content ORDER BY published_at DESC LIMIT ?').all(limit)
res.json({ items: rows })
} catch (err) {
res.status(500).json({ error: err.message })
}
})
router.get('/situation', (req, res) => {
try {
res.json(getSituation())