This commit is contained in:
2023-04-26 22:41:36 +08:00
parent 7f2141e832
commit 6d2c0d8cb3
8 changed files with 37 additions and 8 deletions

1
.gitignore vendored
View File

@@ -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

View File

@@ -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;
}

View File

@@ -1,6 +1,6 @@
const obj = {
begin: false,
limit: 2,
token: process.env.TOKEN || "woshimima",
token: process.env.TOKEN ?? "woshimima",
};
export default obj;

View File

@@ -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());
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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

View File

@@ -27,6 +27,9 @@ class Store {
}
public async update(record: Record<string, string>) {
this.record = record;
await this.save();
}
public async save() {
await write(this.filename, JSON.stringify(this.record), "utf8");
}
}