控制开始时间
This commit is contained in:
27
pages/api/time/started.js
Normal file
27
pages/api/time/started.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import { authenticate, getStarted, setStarted } from "../../../libs/db";
|
||||
|
||||
export default function handler(req, res) {
|
||||
// get method
|
||||
if (req.method === "GET") {
|
||||
res.setHeader("Cache-Control", "no-cache no-store must-revalidate");
|
||||
res.status(200).json(getStarted());
|
||||
return;
|
||||
} else if (req.method === "PUT") {
|
||||
// authenticate
|
||||
const { token } = req.body;
|
||||
if (!authenticate(token)) {
|
||||
res.status(401).json({
|
||||
error: `token ${token} 验证失败`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
// set method
|
||||
const { started } = req.body;
|
||||
setStarted(started);
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
});
|
||||
} else {
|
||||
res.status(405).send({ error: "方法" + req.method + "不被允许" });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user