refactor: 一批名不副实的命名改掉(只动一端,不碰契约)

后端:
- getUserByToken → authenticateToken:它会删会话、续 TTL、记在线,不是纯读
- todayStart → dayStart(instant):本来就接受任意时刻,不只是「今天」
- objectValue → asRecord,删掉 4 份一模一样的私有拷贝和 `as toObject` 别名
- 报错文案 "does not exists" / "Already be a public problem" 改通顺

前端:
- utils/types 里 Contest / User / Problem 三个别名删掉:Contest 原来指后台
  比赛、契约里同名的却是学生侧。现在 Contest = 学生侧、AdminContest = 后台,
  后台用户表单叫 AdminUserForm,题目详情直接用 ProblemDetail
- SubmissionInfo → ContestSubmissionInfo,免得和 submission.info 撞名
- utoa / atou → compressToBase64 / decompressFromBase64(实际是 zlib + base64),
  encode / decode → base64EncodeUtf8 / base64DecodeUtf8
- filterResult → toProblemRow、toProblemListItem → toAdminProblemRow,
  行字段 submission / rate → submissionCount / acRate
- 组件:Modal → AddFromLibraryModal、Form → EditorToolbar、
  ContestEditor → BasicEditor(题单也在用它)、rank 的 Index → RankMedal、
  Name → UserNameCell、Password → PasswordCell、ContestType → ContestAccessTag

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
xuyueandClaude Opus 5.5 committed 2026-09-27 16:08:21 +08:00
1 parent 572a818d49
commit 5ae830a7f9
62 files changed
+284 -320

No files matched your search

+2 -2
View File
@@ -25,7 +25,7 @@ import { publishConfigUpdate } from "../../events"
import { failure, parseBody, success } from "../../http"
import { sniffImageExtension } from "../../services/image"
import { getWebsiteOptions } from "../../services/options"
import { todayStart } from "../../time"
import { dayStart } from "../../time"
import { queryInteger } from "../helpers"
export const adminConfRoutes = new Hono<AppEnv>()
@@ -232,7 +232,7 @@ adminConfRoutes.get("/dashboard", requireSuperAdmin, async (c) => {
db
.select({ value: count() })
.from(schema.submission)
.where(gte(schema.submission.createTime, todayStart())),
.where(gte(schema.submission.createTime, dayStart())),
db
.select({ value: count() })
.from(schema.contest)
+9 -9
View File
@@ -48,7 +48,7 @@ import { config } from "../../config"
import { readFile } from "node:fs/promises"
import { resolve } from "node:path"
import { getTopReactions } from "../../services/reaction"
import { objectValue, queryInteger, sampleUser } from "../helpers"
import { asRecord, queryInteger, sampleUser } from "../helpers"
export const adminProblemRoutes = new Hono<AppEnv>()
@@ -205,7 +205,7 @@ async function serialize(row: ProblemRow) {
source: row.source,
submissionNumber: row.submissionNumber,
acceptedNumber: row.acceptedNumber,
statisticInfo: objectValue(row.statisticInfo),
statisticInfo: asRecord(row.statisticInfo),
contestId: row.contestId,
createdBy: sampleUser(
creator ?? { id: row.createdById, username: "" },
@@ -616,9 +616,9 @@ adminProblemRoutes.delete(
.where(eq(schema.problem.id, id))
.limit(1)
if (!existing)
return failure(c, 404, "problem-not-found", "Problem does not exists")
return failure(c, 404, "problem-not-found", "Problem does not exist")
if (!(await canEdit(c.get("user")!, existing))) {
return failure(c, 404, "problem-not-found", "Problem does not exists")
return failure(c, 404, "problem-not-found", "Problem does not exist")
}
return deleteProblem(c, id)
},
@@ -793,7 +793,7 @@ adminProblemRoutes.post(
return failure(c, 404, "problem-not-found", "Problem does not exist")
}
if (!problem.contestId || problem.isPublic) {
return failure(c, 409, "already-public", "Already be a public problem")
return failure(c, 409, "already-public", "Already a public problem")
}
const [duplicate] = await db
.select({ id: schema.problem.id })
@@ -936,9 +936,9 @@ adminProblemRoutes.get(
)
.limit(1)
if (!problem)
return failure(c, 404, "problem-not-found", "Problem does not exists")
return failure(c, 404, "problem-not-found", "Problem does not exist")
if (!(await canEdit(c.get("user")!, problem))) {
return failure(c, 404, "problem-not-found", "Problem does not exists")
return failure(c, 404, "problem-not-found", "Problem does not exist")
}
try {
const archive = await packTestCaseZip(problem.testCaseId)
@@ -973,9 +973,9 @@ adminProblemRoutes.get(
)
.limit(1)
if (!problem)
return failure(c, 404, "problem-not-found", "Problem does not exists")
return failure(c, 404, "problem-not-found", "Problem does not exist")
if (!(await canEdit(c.get("user")!, problem))) {
return failure(c, 404, "problem-not-found", "Problem does not exists")
return failure(c, 404, "problem-not-found", "Problem does not exist")
}
const info = await readInfo(problem.testCaseId)
if (!info)
+2 -2
View File
@@ -15,7 +15,7 @@ import { requireSuperAdmin, type AppEnv } from "../../auth/middleware"
import { db, schema } from "../../db"
import { failure, parseBody, success } from "../../http"
import { exerciseDataError } from "../../services/exercise"
import { objectValue, queryInteger, sampleUser } from "../helpers"
import { asRecord, queryInteger, sampleUser } from "../helpers"
export const adminTutorialRoutes = new Hono<AppEnv>()
@@ -156,7 +156,7 @@ function serializeExercise(row: typeof schema.exercise.$inferSelect) {
return {
id: row.id,
type: row.type,
data: objectValue(row.data),
data: asRecord(row.data),
order: row.order,
} satisfies AdminExercise
}