更新首页

This commit is contained in:
cheney
2026-08-06 16:41:47 +08:00
parent 547181d333
commit 4d02439ecb
32 changed files with 5470 additions and 93 deletions
+13 -8
View File
@@ -8,16 +8,21 @@ router.use(authRequired)
// 报警列表: 按时间最新优先, cursor 分页 (cursor = id)
router.get('/alerts', async (req, res, next) => {
try {
const limit = Math.min(Number(req.query.limit) || 10, 50)
const cursor = req.query.cursor ? Number(req.query.cursor) : null
const rawLimit = Number(req.query.limit)
const limit = Number.isFinite(rawLimit) && rawLimit >= 1 ? Math.min(Math.floor(rawLimit), 50) : 10
const rawCursor = Number(req.query.cursor)
const cursor = Number.isInteger(rawCursor) && rawCursor > 0 ? rawCursor : null
const where = cursor ? { id: { lt: cursor } } : {}
const items = await prisma.alert.findMany({
where,
orderBy: { id: 'desc' },
take: limit,
})
const [items, total] = await Promise.all([
prisma.alert.findMany({
where,
orderBy: { id: 'desc' },
take: limit,
}),
prisma.alert.count(),
])
const nextCursor = items.length === limit ? String(items[items.length - 1].id) : null
res.json({ items, nextCursor })
res.json({ items, nextCursor, total })
} catch (e) { next(e) }
})