fix
This commit is contained in:
@@ -2,7 +2,7 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { store, html } from "@/store";
|
||||
import config from "@/config";
|
||||
|
||||
export default function handler(
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<Record<string, string>>
|
||||
) {
|
||||
@@ -16,5 +16,6 @@ export default function handler(
|
||||
const json = req.body;
|
||||
store.update(json);
|
||||
}
|
||||
await store.save();
|
||||
res.status(200).json(store.get());
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import config from "@/config";
|
||||
export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (req.method === "POST") {
|
||||
if (req.headers.token !== config.token) {
|
||||
console.log("wrong token", req.headers.token, config.token);
|
||||
res.status(403).json({ error: "wrong token" });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (req.method === "POST") {
|
||||
if (!config.begin) {
|
||||
res.status(400).json({
|
||||
error: "还没到开时间哦",
|
||||
error: "还没到开始时间哦",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -5,8 +5,9 @@ import { get, post } from "@/common";
|
||||
const ControlPage = () => {
|
||||
const [isBegin, setIsBegin] = React.useState(false);
|
||||
const [inputLimit, setInputLimit] = React.useState("2");
|
||||
const [token, setToken] = React.useState("");
|
||||
const toggleBegin = async () => {
|
||||
const json = await post("/api/config", { begin: !isBegin });
|
||||
const json = await post("/api/config", { begin: !isBegin }, { token });
|
||||
setIsBegin(json.begin);
|
||||
};
|
||||
const refresh = async () => {
|
||||
@@ -26,9 +27,16 @@ const ControlPage = () => {
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
</Head>
|
||||
<main>
|
||||
<p>
|
||||
<input
|
||||
value={token}
|
||||
onChange={(event) => setToken(event.target.value)}
|
||||
placeholder="Token"
|
||||
/>
|
||||
</p>
|
||||
<p>
|
||||
<button onClick={() => toggleBegin()}>
|
||||
{isBegin ? "Begin" : "Pause"}
|
||||
{isBegin ? "Pause" : "Begin"}
|
||||
</button>
|
||||
</p>
|
||||
<p>
|
||||
@@ -40,9 +48,13 @@ const ControlPage = () => {
|
||||
/>
|
||||
<button
|
||||
onClick={() => {
|
||||
post("/api/config", {
|
||||
limit: parseInt(inputLimit) || 2,
|
||||
});
|
||||
post(
|
||||
"/api/config",
|
||||
{
|
||||
limit: parseInt(inputLimit) || 2,
|
||||
},
|
||||
{ token }
|
||||
);
|
||||
}}
|
||||
>
|
||||
Set Limit
|
||||
|
||||
Reference in New Issue
Block a user