一些微小的贡献

This commit is contained in:
KirinBaka
2025-04-22 15:19:28 +08:00
parent a04f1c22c9
commit bebf2c9640
7 changed files with 26 additions and 13 deletions

View File

@@ -115,7 +115,7 @@ const Timetable = ({
tds.length = 0;
const table = target.children[0];
table.setAttribute("border", "1");
table.setAttribute("border", "0");
// mark cell
const conflictsTmp: ConflictsTmp = {};
@@ -266,6 +266,7 @@ const Timetable = ({
<>
<h2 style={{ textAlign: "center" }}>Login as {user}</h2>
<div
align="center"
ref={ref}
contentEditable={editable}
style={{

BIN
data-init.zip Normal file

Binary file not shown.

View File

@@ -6,7 +6,7 @@
"esbuild": "./node_modules/.bin/esbuild --bundle --tsconfig=entrypoints/tsconfig.json --alias:'@'='./' --outdir=entrypoints --splitting --format=esm entrypoints/index.tsx entrypoints/edit/index.tsx entrypoints/report/index.tsx entrypoints/control/index.tsx --minify",
"dev": "next dev",
"build": "next build",
"start": "next start",
"start": "next start -p 4000",
"lint": "next lint"
},
"dependencies": {

View File

@@ -4,13 +4,14 @@ 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);
console.log("api::config: wrong token", req.headers.token, config.token);
res.status(403).json({ error: "wrong token" });
return;
}
// update config
config.begin = req.body.begin ?? config.begin;
config.limit = req.body.limit ?? config.limit;
console.log("api::config: update config", config);
}
res.status(200).json(config);
}

View File

@@ -5,6 +5,7 @@ import config from "@/config";
export default function handler(req: NextApiRequest, res: NextApiResponse) {
const store = storeProxy.get();
// console.log("api::store.null()", store);
if (req.method === "POST") {
if (!config.begin) {
res.status(400).json({
@@ -13,7 +14,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
return;
}
const json = req.body;
console.log("request", json);
console.log("api::request: new request", json);
if (json.checked) {
let count = 0;
for (const name in store) {
@@ -21,13 +22,13 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
count += 1;
if (count >= config.limit) {
res.status(403).json({
error: `超过选择数量限制: ${config.limit}`,
error: `超过选择数量限制,您至多选 ${config.limit} 个班.`,
});
return;
}
}
}
// check whether it is alreadly occupied
// check whether it is already occupied
if (store[json.name] !== undefined) {
res.status(403).json({
error: `当前位置已被他人占用`,
@@ -46,8 +47,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
delete store[json.name];
}
}
console.log("query", req.query);
const resp = {
const resp: { occupied: string[], myselect: string[] } = { // try to fix
occupied: [],
myselect: [],
};

View File

@@ -9,9 +9,9 @@ export default function Home() {
return (
<>
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title> </title>
<meta name="description" content="ITSC抢班系统" />
{/* <meta name="viewport" content="width=device-width, initial-scale=1" /> */}
<link rel="icon" href="/favicon.ico" />
</Head>
<main>

View File

@@ -30,7 +30,13 @@ class Store {
await this.save();
}
public async save() {
await write(this.filename, JSON.stringify(this.record), "utf8");
// try first, then catch
try {
console.log("store::index: save record", this.record);
await write(this.filename, JSON.stringify(this.record), "utf8");
} catch {
console.error("store::index: save record error, filename:", this.filename);
}
}
}
@@ -52,7 +58,12 @@ class HTML {
public async set(html: string) {
this.html = html;
// store into file
await write(this.filename, html, "utf8");
// try first, then catch
try {
await write(this.filename, html, "utf8");
} catch {
console.error("store::index: save record error, filename:", this.filename);
}
}
}