fix: 搜索路由参数校验 — page>=1、limit 1-500
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user