fix: 搜索路由参数校验 — page>=1、limit 1-500

This commit is contained in:
2026-05-20 02:46:13 +08:00
parent d7b055f88b
commit c4ca8edd58
53 changed files with 855 additions and 21 deletions

View File

@@ -289,6 +289,17 @@ router.get('/search', searchLimiter, async (req: Request, res: Response) => {
res.status(400).json({ error: 'Query parameter "q" is required' });
return;
}
if (isNaN(page) || page < 1) {
res.status(400).json({ error: 'Page must be >= 1' });
return;
}
if (req.query.limit !== undefined) {
const limit = parseInt(req.query.limit as string, 10);
if (isNaN(limit) || limit < 1 || limit > 500) {
res.status(400).json({ error: 'Limit must be 1-500' });
return;
}
}
const result = await search(keyword, page, ip);