feat: add size limit for 'search by gid' api
This commit is contained in:
parent
18a137e441
commit
fa23178baf
@ -210,18 +210,26 @@ function getRescanDocumentHandler(controller: DocumentAccessor) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getContentRouter = (controller: DocumentAccessor) => {
|
function ContentGidListHandler(controller: DocumentAccessor) {
|
||||||
const ret = new Router();
|
return async (ctx: Context, next: Next) => {
|
||||||
ret.get("/search", PerCheck(Per.QueryContent), ContentQueryHandler(controller));
|
|
||||||
ret.get("/_gid", PerCheck(Per.QueryContent), async (ctx, next) => {
|
|
||||||
const gid_list = ParseQueryArray(ctx.query.gid).map((x) => Number.parseInt(x))
|
const gid_list = ParseQueryArray(ctx.query.gid).map((x) => Number.parseInt(x))
|
||||||
if (gid_list.some((x) => Number.isNaN(x))) {
|
if (gid_list.some((x) => Number.isNaN(x))) {
|
||||||
return sendError(400, "gid is not a number");
|
return sendError(400, "gid is not a number");
|
||||||
}
|
}
|
||||||
|
// size limit
|
||||||
|
if (gid_list.length > 100) {
|
||||||
|
return sendError(400, "gid list is too long");
|
||||||
|
}
|
||||||
const r = await controller.findByGidList(gid_list);
|
const r = await controller.findByGidList(gid_list);
|
||||||
ctx.body = r;
|
ctx.body = r;
|
||||||
ctx.type = "json";
|
ctx.type = "json";
|
||||||
});
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getContentRouter = (controller: DocumentAccessor) => {
|
||||||
|
const ret = new Router();
|
||||||
|
ret.get("/search", PerCheck(Per.QueryContent), ContentQueryHandler(controller));
|
||||||
|
ret.get("/_gid", PerCheck(Per.QueryContent), ContentGidListHandler(controller));
|
||||||
ret.get("/:num(\\d+)", PerCheck(Per.QueryContent), ContentIDHandler(controller));
|
ret.get("/:num(\\d+)", PerCheck(Per.QueryContent), ContentIDHandler(controller));
|
||||||
ret.all("/:num(\\d+)/(.*)", PerCheck(Per.QueryContent), ContentHandler(controller));
|
ret.all("/:num(\\d+)/(.*)", PerCheck(Per.QueryContent), ContentHandler(controller));
|
||||||
ret.post("/:num(\\d+)", AdminOnly, UpdateContentHandler(controller));
|
ret.post("/:num(\\d+)", AdminOnly, UpdateContentHandler(controller));
|
||||||
|
Loading…
Reference in New Issue
Block a user