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:
1 parent
572a818d49
commit
5ae830a7f9
62 files changed
+284
-320
No files matched your search
@@ -16,7 +16,7 @@ import { publishAchievementNotification } from "../events"
|
||||
import { calendarDay, dayNumber, localHour } from "../time"
|
||||
import { findMetric } from "./achievement-metrics"
|
||||
import { isAccepted, JudgeStatus } from "../judge/status"
|
||||
import { objectValue } from "../routes/helpers"
|
||||
import { asRecord } from "../routes/helpers"
|
||||
|
||||
function numberMetric(metrics: Record<string, unknown>, key: string) {
|
||||
const value = metrics[key]
|
||||
@@ -129,7 +129,7 @@ export async function updateAchievementsForSubmission(submissionId: string) {
|
||||
.where(eq(schema.userStat.userId, row.submission.userId))
|
||||
.for("update")
|
||||
if (!stat) throw new Error("User achievement stat could not be created")
|
||||
const value = objectValue(stat.metrics)
|
||||
const value = asRecord(stat.metrics)
|
||||
value.submission_count = numberMetric(value, "submission_count") + 1
|
||||
if (firstAc) {
|
||||
value.accepted_count = numberMetric(value, "accepted_count") + 1
|
||||
@@ -143,7 +143,7 @@ export async function updateAchievementsForSubmission(submissionId: string) {
|
||||
numberMetric(value, "max_wa_before_ac"),
|
||||
priorRows.length,
|
||||
)
|
||||
const perDay = objectValue(value._ac_per_day)
|
||||
const perDay = asRecord(value._ac_per_day)
|
||||
perDay[date] = (typeof perDay[date] === "number" ? perDay[date] : 0) + 1
|
||||
value._ac_per_day = perDay
|
||||
value.max_ac_in_one_day = Math.max(
|
||||
@@ -264,7 +264,7 @@ export async function updateAchievementsForProblemSet(userId: number) {
|
||||
.for("update")
|
||||
.limit(1)
|
||||
if (!stat) throw new Error("User achievement stat could not be created")
|
||||
const value = objectValue(stat.metrics)
|
||||
const value = asRecord(stat.metrics)
|
||||
value.badge_count = badgeRow?.value ?? 0
|
||||
value.problemset_completed = completedRow?.value ?? 0
|
||||
await tx
|
||||
@@ -345,7 +345,7 @@ export async function rescanAchievement(achievementId: number) {
|
||||
.from(schema.userStat)
|
||||
const eligible = stats.filter((stat) => {
|
||||
if (already.has(stat.userId)) return false
|
||||
const value = objectValue(stat.metrics)[achievement.metric]
|
||||
const value = asRecord(stat.metrics)[achievement.metric]
|
||||
if (typeof value !== "number") return false
|
||||
return achievement.operator === "gte"
|
||||
? value >= achievement.threshold
|
||||
|
||||
@@ -13,7 +13,7 @@ import { and, desc, eq, isNotNull } from "drizzle-orm"
|
||||
import { config } from "../config"
|
||||
import { db, schema } from "../db"
|
||||
import { JudgeStatus, judgeStatusName } from "../judge/status"
|
||||
import { objectValue } from "../routes/helpers"
|
||||
import { asRecord } from "../routes/helpers"
|
||||
import { completeChat } from "./ai"
|
||||
import { KEY_LINE_LEVEL } from "./hint-filter"
|
||||
import { readInfo } from "./test-case"
|
||||
@@ -80,7 +80,7 @@ const SINGLE_SYSTEM =
|
||||
"你是编程助教。指出学生代码最关键的一个问题,循序渐进地提示,绝不直接给出核心算法或完整解法。输入读取错误可以直接给出正确片段。使用 Markdown,不超过6句话。"
|
||||
|
||||
function errInfo(row: HintRow) {
|
||||
return String(objectValue(row.submission.statisticInfo).err_info ?? "无")
|
||||
return String(asRecord(row.submission.statisticInfo).err_info ?? "无")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +122,7 @@ function problemBrief(row: HintRow) {
|
||||
const samples = (
|
||||
Array.isArray(row.problem.samples) ? row.problem.samples : []
|
||||
)
|
||||
.map((item) => objectValue(item))
|
||||
.map((item) => asRecord(item))
|
||||
.filter(
|
||||
(item): item is { input: string; output: string } =>
|
||||
typeof item.input === "string" && typeof item.output === "string",
|
||||
@@ -152,7 +152,7 @@ function numbered(code: string) {
|
||||
/** 同语言的标准答案优先;没有就拿别的语言的(思路一样,照样能帮诊断);再没有就 null */
|
||||
export function referenceAnswer(row: HintRow) {
|
||||
const answers = Array.isArray(row.problem.answers)
|
||||
? row.problem.answers.map((item) => objectValue(item))
|
||||
? row.problem.answers.map((item) => asRecord(item))
|
||||
: []
|
||||
const usable = answers.filter(
|
||||
(item): item is { language: string; code: string } =>
|
||||
@@ -174,10 +174,10 @@ export function referenceAnswer(row: HintRow) {
|
||||
*/
|
||||
async function firstFailedCase(row: HintRow) {
|
||||
if (row.submission.language === "SQL") return null
|
||||
const data = objectValue(row.submission.info).data
|
||||
const data = asRecord(row.submission.info).data
|
||||
if (!Array.isArray(data)) return null
|
||||
const failed = data
|
||||
.map((item) => objectValue(item))
|
||||
.map((item) => asRecord(item))
|
||||
.find((item) => typeof item.result === "number" && item.result !== 0)
|
||||
if (!failed || typeof failed.test_case !== "string") return null
|
||||
try {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { and, eq, notInArray, sql } from "drizzle-orm"
|
||||
|
||||
import { db, schema } from "../db"
|
||||
import { objectValue } from "../routes/helpers"
|
||||
import { asRecord } from "../routes/helpers"
|
||||
|
||||
type BadgeRow = typeof schema.problemsetBadge.$inferSelect
|
||||
type ProgressRow = typeof schema.problemsetProgress.$inferSelect
|
||||
@@ -40,7 +40,7 @@ export function computeProgress(
|
||||
if (score === undefined) continue
|
||||
totalScore += score
|
||||
// 分值以题单当前的设置为准,detail 里存的是做出那一刻的快照
|
||||
kept[key] = { ...objectValue(value), score }
|
||||
kept[key] = { ...asRecord(value), score }
|
||||
}
|
||||
// 分母只算必做题。「(选做)」这个标签一直只是卡片上的一行字,进度分母和 all_problems
|
||||
// 奖章照样要求做完 —— 快照里 22 个人做完了全部必做题,界面却显示未完成、全通奖章也拿不到
|
||||
@@ -137,7 +137,7 @@ export function eligibleForBadge(badge: BadgeRow, progress: BadgeCheck) {
|
||||
}
|
||||
if (badge.conditionType === "problem_count") {
|
||||
return (
|
||||
Object.keys(objectValue(progress.progressDetail)).length >=
|
||||
Object.keys(asRecord(progress.progressDetail)).length >=
|
||||
badge.conditionValue
|
||||
)
|
||||
}
|
||||
@@ -232,7 +232,7 @@ export async function resyncProgress(problemsetId: number) {
|
||||
const updated = progresses.map((progress) => ({
|
||||
...progress,
|
||||
...computeProgress(
|
||||
objectValue(progress.progressDetail),
|
||||
asRecord(progress.progressDetail),
|
||||
links,
|
||||
progress.completeTime,
|
||||
now,
|
||||
@@ -309,7 +309,7 @@ export async function recordSolvedProblem(
|
||||
.values({ problemsetId, userId, submissionId, problemId })
|
||||
}
|
||||
|
||||
const detail = objectValue(progress.progressDetail)
|
||||
const detail = asRecord(progress.progressDetail)
|
||||
if (String(problemId) in detail) return []
|
||||
const links = await tx
|
||||
.select({
|
||||
|
||||
@@ -224,7 +224,7 @@ export async function packTestCaseZip(testCaseId: string) {
|
||||
try {
|
||||
entries = await readdir(directory)
|
||||
} catch {
|
||||
throw new TestCaseError("Test case does not exists")
|
||||
throw new TestCaseError("Test case does not exist")
|
||||
}
|
||||
const names = new Set(entries)
|
||||
const isSql = await readInfo(testCaseId)
|
||||
|
||||
Reference in new issue
Block a user