fix
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,6 +3,7 @@
|
|||||||
/hours.json
|
/hours.json
|
||||||
/regular.json
|
/regular.json
|
||||||
/record.json
|
/record.json
|
||||||
|
/store.json
|
||||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
# dependencies
|
# dependencies
|
||||||
|
|||||||
@@ -126,7 +126,18 @@ const Timetable = ({
|
|||||||
for (const td_index in tr.children) {
|
for (const td_index in tr.children) {
|
||||||
const td: HTMLTableCellElement = tr.children[td_index];
|
const td: HTMLTableCellElement = tr.children[td_index];
|
||||||
if (td.tagName !== "TD") continue;
|
if (td.tagName !== "TD") continue;
|
||||||
|
|
||||||
if (td.getAttribute("bgcolor")?.toUpperCase() !== "#39CEFF") {
|
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);
|
row.push(null);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const obj = {
|
const obj = {
|
||||||
begin: false,
|
begin: false,
|
||||||
limit: 2,
|
limit: 2,
|
||||||
token: process.env.TOKEN || "woshimima",
|
token: process.env.TOKEN ?? "woshimima",
|
||||||
};
|
};
|
||||||
export default obj;
|
export default obj;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
|||||||
import { store, html } from "@/store";
|
import { store, html } from "@/store";
|
||||||
import config from "@/config";
|
import config from "@/config";
|
||||||
|
|
||||||
export default function handler(
|
export default async function handler(
|
||||||
req: NextApiRequest,
|
req: NextApiRequest,
|
||||||
res: NextApiResponse<Record<string, string>>
|
res: NextApiResponse<Record<string, string>>
|
||||||
) {
|
) {
|
||||||
@@ -16,5 +16,6 @@ export default function handler(
|
|||||||
const json = req.body;
|
const json = req.body;
|
||||||
store.update(json);
|
store.update(json);
|
||||||
}
|
}
|
||||||
|
await store.save();
|
||||||
res.status(200).json(store.get());
|
res.status(200).json(store.get());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import config from "@/config";
|
|||||||
export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
if (req.method === "POST") {
|
if (req.method === "POST") {
|
||||||
if (req.headers.token !== config.token) {
|
if (req.headers.token !== config.token) {
|
||||||
|
console.log("wrong token", req.headers.token, config.token);
|
||||||
res.status(403).json({ error: "wrong token" });
|
res.status(403).json({ error: "wrong token" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
if (req.method === "POST") {
|
if (req.method === "POST") {
|
||||||
if (!config.begin) {
|
if (!config.begin) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
error: "还没到开时间哦",
|
error: "还没到开始时间哦",
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ import { get, post } from "@/common";
|
|||||||
const ControlPage = () => {
|
const ControlPage = () => {
|
||||||
const [isBegin, setIsBegin] = React.useState(false);
|
const [isBegin, setIsBegin] = React.useState(false);
|
||||||
const [inputLimit, setInputLimit] = React.useState("2");
|
const [inputLimit, setInputLimit] = React.useState("2");
|
||||||
|
const [token, setToken] = React.useState("");
|
||||||
const toggleBegin = async () => {
|
const toggleBegin = async () => {
|
||||||
const json = await post("/api/config", { begin: !isBegin });
|
const json = await post("/api/config", { begin: !isBegin }, { token });
|
||||||
setIsBegin(json.begin);
|
setIsBegin(json.begin);
|
||||||
};
|
};
|
||||||
const refresh = async () => {
|
const refresh = async () => {
|
||||||
@@ -26,9 +27,16 @@ const ControlPage = () => {
|
|||||||
<link rel="icon" href="/favicon.ico" />
|
<link rel="icon" href="/favicon.ico" />
|
||||||
</Head>
|
</Head>
|
||||||
<main>
|
<main>
|
||||||
|
<p>
|
||||||
|
<input
|
||||||
|
value={token}
|
||||||
|
onChange={(event) => setToken(event.target.value)}
|
||||||
|
placeholder="Token"
|
||||||
|
/>
|
||||||
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<button onClick={() => toggleBegin()}>
|
<button onClick={() => toggleBegin()}>
|
||||||
{isBegin ? "Begin" : "Pause"}
|
{isBegin ? "Pause" : "Begin"}
|
||||||
</button>
|
</button>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
@@ -40,9 +48,13 @@ const ControlPage = () => {
|
|||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
post("/api/config", {
|
post(
|
||||||
|
"/api/config",
|
||||||
|
{
|
||||||
limit: parseInt(inputLimit) || 2,
|
limit: parseInt(inputLimit) || 2,
|
||||||
});
|
},
|
||||||
|
{ token }
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Set Limit
|
Set Limit
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ class Store {
|
|||||||
}
|
}
|
||||||
public async update(record: Record<string, string>) {
|
public async update(record: Record<string, string>) {
|
||||||
this.record = record;
|
this.record = record;
|
||||||
|
await this.save();
|
||||||
|
}
|
||||||
|
public async save() {
|
||||||
await write(this.filename, JSON.stringify(this.record), "utf8");
|
await write(this.filename, JSON.stringify(this.record), "utf8");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user