This commit is contained in:
2022-03-31 12:06:31 +08:00
parent 75a366ae11
commit 7e4c106683
10 changed files with 1905 additions and 459 deletions

30
pages/api/time/limit.js Normal file
View File

@@ -0,0 +1,30 @@
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: "Unauthorized",
});
return;
}
// check type is integer
const limitInt = parseInt(limit);
if (!limitInt) {
res.status(400).json({
error: "limit must be integer",
});
return;
}
setLimit(limitInt);
res.status(200).send({ success: true });
} else {
res.status(405).send({ error: "method not allowed" });
}
}