mirror of
https://github.com/ZeroCatDev/ClassworksKV.git
synced 2025-12-07 21:13:10 +00:00
Update validation logic for request body
Allow empty arrays to pass validation while intercepting empty objects.
This commit is contained in:
parent
f0de2cd59b
commit
f985b6a11a
@ -356,12 +356,7 @@ router.post(
|
|||||||
const {key} = req.params;
|
const {key} = req.params;
|
||||||
const value = req.body;
|
const value = req.body;
|
||||||
|
|
||||||
// 【修改点】允许空数组通过校验,但继续拦截真正的空对象 {}
|
|
||||||
// 如果 value 是空数组 [],Object.keys 为 0,但 !Array.isArray 为 false,条件为 false -> 通过
|
|
||||||
// 如果 value 是空对象 {},Object.keys 为 0,且 !Array.isArray 为 true,条件为 true -> 拦截
|
|
||||||
if (!value || (Object.keys(value).length === 0 && !Array.isArray(value))) {
|
|
||||||
return next(errors.createError(400, "请提供有效的JSON值"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取客户端IP
|
// 获取客户端IP
|
||||||
const creatorIp =
|
const creatorIp =
|
||||||
@ -432,4 +427,4 @@ router.delete(
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user