fix:优化整个大屏界面

This commit is contained in:
Daniel
2026-03-02 00:59:40 +08:00
parent 24d0593e12
commit 91d9e48e1e
13 changed files with 314 additions and 101 deletions

View File

@@ -12,6 +12,10 @@ app.use(cors())
app.use(express.json())
app.use('/api', routes)
app.get('/api/health', (_, res) => res.json({ ok: true }))
app.post('/api/crawler/notify', (_, res) => {
notifyCrawlerUpdate()
res.json({ ok: true })
})
const server = http.createServer(app)
@@ -29,6 +33,15 @@ function broadcastSituation() {
}
setInterval(broadcastSituation, 5000)
// 供爬虫调用:更新 situation.updated_at 并立即广播
function notifyCrawlerUpdate() {
try {
const db = require('./db')
db.prepare("INSERT OR REPLACE INTO situation (id, data, updated_at) VALUES (1, '{}', ?)").run(new Date().toISOString())
broadcastSituation()
} catch (_) {}
}
server.listen(PORT, () => {
console.log(`API + WebSocket running at http://localhost:${PORT}`)
})