diff --git a/.gitignore b/.gitignore index c27c882..0a3b136 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /hours.json /regular.json /record.json +/store.json # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # dependencies diff --git a/components/Timetable.tsx b/components/Timetable.tsx index 53dce44..dcb4b64 100644 --- a/components/Timetable.tsx +++ b/components/Timetable.tsx @@ -126,7 +126,18 @@ const Timetable = ({ for (const td_index in tr.children) { const td: HTMLTableCellElement = tr.children[td_index]; if (td.tagName !== "TD") continue; + if (td.getAttribute("bgcolor")?.toUpperCase() !== "#39CEFF") { + // const position (assigned by supervisor) + if (td?.textContent?.trim() === user) { + const constSelected = document.createElement("input"); + constSelected.setAttribute("type", "checkbox"); + constSelected.setAttribute("checked", "1"); + constSelected.setAttribute("disabled", "1"); + td.innerHTML = ""; + td.appendChild(constSelected); + } + row.push(null); continue; } diff --git a/config/index.ts b/config/index.ts index 137ee42..00e5af4 100644 --- a/config/index.ts +++ b/config/index.ts @@ -1,6 +1,6 @@ const obj = { begin: false, limit: 2, - token: process.env.TOKEN || "woshimima", + token: process.env.TOKEN ?? "woshimima", }; export default obj; diff --git a/pages/api/admin.ts b/pages/api/admin.ts index 8d54928..d9e706d 100644 --- a/pages/api/admin.ts +++ b/pages/api/admin.ts @@ -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> ) { @@ -16,5 +16,6 @@ export default function handler( const json = req.body; store.update(json); } + await store.save(); res.status(200).json(store.get()); } diff --git a/pages/api/config.ts b/pages/api/config.ts index fae065a..54b37d0 100644 --- a/pages/api/config.ts +++ b/pages/api/config.ts @@ -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; } diff --git a/pages/api/record.ts b/pages/api/record.ts index bfce8ac..a71ad3f 100644 --- a/pages/api/record.ts +++ b/pages/api/record.ts @@ -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; } diff --git a/pages/control.tsx b/pages/control.tsx index 0b7873d..b078040 100644 --- a/pages/control.tsx +++ b/pages/control.tsx @@ -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 = () => {
+

+ setToken(event.target.value)} + placeholder="Token" + /> +

@@ -40,9 +48,13 @@ const ControlPage = () => { />