31 lines
732 B
JavaScript
31 lines
732 B
JavaScript
import { authenticate, setLimit } from "../../../libs/db";
|
|
|
|
export default function handler(req, res) {
|
|
// put method
|
|
if (req.method === "PUT") {
|
|
const { token, limit } = req.body;
|
|
|
|
// authenticate
|
|
if (!authenticate(token)) {
|
|
res.status(401).json({
|
|
error: `token ${token} 验证失败`,
|
|
});
|
|
return;
|
|
}
|
|
|
|
// check type is integer
|
|
const limitInt = parseInt(limit);
|
|
if (!limitInt) {
|
|
res.status(400).json({
|
|
error: `数量限制必须是整数,但是传入了 ${limit}`,
|
|
});
|
|
return;
|
|
}
|
|
|
|
setLimit(limitInt);
|
|
res.status(200).send({ success: true });
|
|
} else {
|
|
res.status(405).send({ error: "方法" + req.method + "不被允许" });
|
|
}
|
|
}
|