1 parent
23844ae301
commit
d25b5dbe6d
268 files changed
+3684
-8861
No files matched your search
@@ -1,11 +1,6 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const achievementRaritySchema = z.enum([
|
||||
"bronze",
|
||||
"silver",
|
||||
"gold",
|
||||
"platinum",
|
||||
])
|
||||
export const achievementRaritySchema = z.enum(["bronze", "silver", "gold", "platinum"])
|
||||
|
||||
export const achievementSchema = z.object({
|
||||
id: z.number().int(),
|
||||
@@ -71,8 +66,6 @@ export type PendingAchievement = z.infer<typeof pendingAchievementSchema>
|
||||
export type AchievementSummary = z.infer<typeof achievementSummarySchema>
|
||||
export type AchievementRarity = z.infer<typeof achievementRaritySchema>
|
||||
export type AchievementRarityStat = z.infer<typeof achievementRarityStatSchema>
|
||||
export type AchievementNotification = z.infer<
|
||||
typeof achievementNotificationSchema
|
||||
>
|
||||
export type AchievementNotification = z.infer<typeof achievementNotificationSchema>
|
||||
|
||||
export type MarkAchievementsRead = z.infer<typeof markAchievementsReadSchema>
|
||||
+38
-120
@@ -41,9 +41,7 @@ export const adminAnnouncementListItemSchema = adminAnnouncementSchema.omit({
|
||||
content: true,
|
||||
})
|
||||
|
||||
export const adminAnnouncementListSchema = paginatedSchema(
|
||||
adminAnnouncementListItemSchema,
|
||||
)
|
||||
export const adminAnnouncementListSchema = paginatedSchema(adminAnnouncementListItemSchema)
|
||||
|
||||
export const createAnnouncementRequestSchema = z.object({
|
||||
title: z.string().trim().min(1).max(64),
|
||||
@@ -59,9 +57,7 @@ export type ProblemSample = z.infer<typeof problemSampleSchema>
|
||||
export type ProblemAnswer = z.infer<typeof problemAnswerSchema>
|
||||
export type ProblemTestCaseScore = z.infer<typeof problemTestCaseScoreSchema>
|
||||
export type AdminAnnouncement = z.infer<typeof adminAnnouncementSchema>
|
||||
export type AdminAnnouncementListItem = z.infer<
|
||||
typeof adminAnnouncementListItemSchema
|
||||
>
|
||||
export type AdminAnnouncementListItem = z.infer<typeof adminAnnouncementListItemSchema>
|
||||
|
||||
// ---------------------------------------------------------------- 教程 / 练习
|
||||
|
||||
@@ -157,9 +153,7 @@ export const adminAiReportSchema = z.object({
|
||||
analysis: z.string(),
|
||||
})
|
||||
|
||||
export const adminAiReportListSchema = paginatedSchema(
|
||||
adminAiReportListItemSchema,
|
||||
)
|
||||
export const adminAiReportListSchema = paginatedSchema(adminAiReportListItemSchema)
|
||||
export const toggleAiReportPinResponseSchema = z.object({
|
||||
isPinned: z.boolean(),
|
||||
})
|
||||
@@ -244,14 +238,7 @@ export const updateUserRequestSchema = z.object({
|
||||
/** 导入用户:每行 [用户名, 密码, 邮箱, 真名],与前端粘贴的 Excel 列序一致 */
|
||||
export const importUsersRequestSchema = z.object({
|
||||
users: z
|
||||
.array(
|
||||
z.tuple([
|
||||
z.string().trim().min(1).max(32),
|
||||
z.string().min(1),
|
||||
z.string(),
|
||||
z.string(),
|
||||
]),
|
||||
)
|
||||
.array(z.tuple([z.string().trim().min(1).max(32), z.string().min(1), z.string(), z.string()]))
|
||||
.min(1),
|
||||
})
|
||||
|
||||
@@ -381,11 +368,7 @@ export const updateAcmHelperRequestSchema = z.object({
|
||||
|
||||
export const problemSetDifficultySchema = z.enum(["Easy", "Medium", "Hard"])
|
||||
export const problemSetStatusSchema = z.enum(["draft", "active", "archived"])
|
||||
export const badgeConditionTypeSchema = z.enum([
|
||||
"all_problems",
|
||||
"problem_count",
|
||||
"score",
|
||||
])
|
||||
export const badgeConditionTypeSchema = z.enum(["all_problems", "problem_count", "score"])
|
||||
|
||||
export const adminProblemSetSchema = z.object({
|
||||
id: z.number().int(),
|
||||
@@ -468,8 +451,7 @@ export const createProblemSetBadgeRequestSchema = z.object({
|
||||
conditionValue: z.number().int().default(0),
|
||||
})
|
||||
|
||||
export const updateProblemSetBadgeRequestSchema =
|
||||
createProblemSetBadgeRequestSchema
|
||||
export const updateProblemSetBadgeRequestSchema = createProblemSetBadgeRequestSchema
|
||||
|
||||
export const adminProblemSetProgressSchema = z.object({
|
||||
id: z.number().int(),
|
||||
@@ -648,14 +630,10 @@ export const adminProblemListItemSchema = z.object({
|
||||
showFlowchart: z.boolean(),
|
||||
// 最高票评价 {type, count}。**只有公开题列表下发**,比赛题列表恒传 null ——
|
||||
// 与旧后端 reaction/services.py:get_top_reactions 的口径一致。
|
||||
topReaction: z
|
||||
.object({ type: reactionKeySchema, count: z.number().int() })
|
||||
.nullable(),
|
||||
topReaction: z.object({ type: reactionKeySchema, count: z.number().int() }).nullable(),
|
||||
})
|
||||
|
||||
export const adminProblemListSchema = paginatedSchema(
|
||||
adminProblemListItemSchema,
|
||||
)
|
||||
export const adminProblemListSchema = paginatedSchema(adminProblemListItemSchema)
|
||||
|
||||
/**
|
||||
* 题面样例 / 标准答案 / 测试点分值。这三个旧后端都是逐字段校验的
|
||||
@@ -867,132 +845,72 @@ export type AdminAiReport = z.infer<typeof adminAiReportSchema>
|
||||
export type AdminAiReportList = z.infer<typeof adminAiReportListSchema>
|
||||
export type StuckProblem = z.infer<typeof stuckProblemSchema>
|
||||
export type LearnStudentProgress = z.infer<typeof learnStudentProgressSchema>
|
||||
export type LearnStudentProgressList = z.infer<
|
||||
typeof learnStudentProgressListSchema
|
||||
>
|
||||
export type LearnStudentProgressList = z.infer<typeof learnStudentProgressListSchema>
|
||||
export type LearnTutorialProgress = z.infer<typeof learnTutorialProgressSchema>
|
||||
export type LearnTutorialProgressList = z.infer<
|
||||
typeof learnTutorialProgressListSchema
|
||||
>
|
||||
export type LearnTutorialProgressList = z.infer<typeof learnTutorialProgressListSchema>
|
||||
export type LearnExerciseProgress = z.infer<typeof learnExerciseProgressSchema>
|
||||
export type LearnExerciseProgressList = z.infer<
|
||||
typeof learnExerciseProgressListSchema
|
||||
>
|
||||
export type LearnExerciseProgressList = z.infer<typeof learnExerciseProgressListSchema>
|
||||
export type LearnExerciseAttempt = z.infer<typeof learnExerciseAttemptSchema>
|
||||
export type AcTrend = z.infer<typeof acTrendSchema>
|
||||
|
||||
export type AdminTag = z.infer<typeof adminTagSchema>
|
||||
export type RenameTagResponse = z.infer<typeof renameTagResponseSchema>
|
||||
export type BatchProblemTagResponse = z.infer<
|
||||
typeof batchProblemTagResponseSchema
|
||||
>
|
||||
export type BatchProblemTagResponse = z.infer<typeof batchProblemTagResponseSchema>
|
||||
export type SqlTestCaseScript = z.infer<typeof sqlTestCaseScriptSchema>
|
||||
export type GenerateSqlTestCaseResponse = z.infer<
|
||||
typeof generateSqlTestCaseResponseSchema
|
||||
>
|
||||
export type AdminProblemSetProgress = z.infer<
|
||||
typeof adminProblemSetProgressSchema
|
||||
>
|
||||
export type GenerateSqlTestCaseResponse = z.infer<typeof generateSqlTestCaseResponseSchema>
|
||||
export type AdminProblemSetProgress = z.infer<typeof adminProblemSetProgressSchema>
|
||||
|
||||
export type AdminAnnouncementList = z.infer<typeof adminAnnouncementListSchema>
|
||||
export type CreateAnnouncementRequest = z.infer<
|
||||
typeof createAnnouncementRequestSchema
|
||||
>
|
||||
export type UpdateAnnouncementRequest = z.infer<
|
||||
typeof updateAnnouncementRequestSchema
|
||||
>
|
||||
export type CreateAnnouncementRequest = z.infer<typeof createAnnouncementRequestSchema>
|
||||
export type UpdateAnnouncementRequest = z.infer<typeof updateAnnouncementRequestSchema>
|
||||
export type TutorialType = z.infer<typeof tutorialTypeSchema>
|
||||
export type AdminTutorial = z.infer<typeof adminTutorialSchema>
|
||||
export type AdminTutorialListItem = z.infer<typeof adminTutorialListItemSchema>
|
||||
export type AdminTutorialGroups = z.infer<typeof adminTutorialGroupsSchema>
|
||||
export type CreateTutorialRequest = z.infer<typeof createTutorialRequestSchema>
|
||||
export type UpdateTutorialRequest = z.infer<typeof updateTutorialRequestSchema>
|
||||
export type SetTutorialVisibilityRequest = z.infer<
|
||||
typeof setTutorialVisibilityRequestSchema
|
||||
>
|
||||
export type SetTutorialVisibilityRequest = z.infer<typeof setTutorialVisibilityRequestSchema>
|
||||
export type ExerciseType = z.infer<typeof exerciseTypeSchema>
|
||||
export type AdminExercise = z.infer<typeof adminExerciseSchema>
|
||||
export type CreateExerciseRequest = z.infer<typeof createExerciseRequestSchema>
|
||||
export type UpdateExerciseRequest = z.infer<typeof updateExerciseRequestSchema>
|
||||
export type ToggleAiReportPinResponse = z.infer<
|
||||
typeof toggleAiReportPinResponseSchema
|
||||
>
|
||||
export type ToggleAiReportPinResponse = z.infer<typeof toggleAiReportPinResponseSchema>
|
||||
export type AchievementOperator = z.infer<typeof achievementOperatorSchema>
|
||||
export type CreateAchievementRequest = z.infer<
|
||||
typeof createAchievementRequestSchema
|
||||
>
|
||||
export type UpdateAchievementRequest = z.infer<
|
||||
typeof updateAchievementRequestSchema
|
||||
>
|
||||
export type CreateAchievementRequest = z.infer<typeof createAchievementRequestSchema>
|
||||
export type UpdateAchievementRequest = z.infer<typeof updateAchievementRequestSchema>
|
||||
export type UpdateUserRequest = z.infer<typeof updateUserRequestSchema>
|
||||
export type ImportUsersRequest = z.infer<typeof importUsersRequestSchema>
|
||||
export type DeleteUsersRequest = z.infer<typeof deleteUsersRequestSchema>
|
||||
export type ResetPasswordResponse = z.infer<typeof resetPasswordResponseSchema>
|
||||
export type UpdateWebsiteConfigRequest = z.infer<
|
||||
typeof updateWebsiteConfigRequestSchema
|
||||
>
|
||||
export type UpdateJudgeServerRequest = z.infer<
|
||||
typeof updateJudgeServerRequestSchema
|
||||
>
|
||||
export type UpdateWebsiteConfigRequest = z.infer<typeof updateWebsiteConfigRequestSchema>
|
||||
export type UpdateJudgeServerRequest = z.infer<typeof updateJudgeServerRequestSchema>
|
||||
export type UploadImageResponse = z.infer<typeof uploadImageResponseSchema>
|
||||
export type CreateContestRequest = z.infer<typeof createContestRequestSchema>
|
||||
export type UpdateContestRequest = z.infer<typeof updateContestRequestSchema>
|
||||
export type UpdateAcmHelperRequest = z.infer<
|
||||
typeof updateAcmHelperRequestSchema
|
||||
>
|
||||
export type UpdateAcmHelperRequest = z.infer<typeof updateAcmHelperRequestSchema>
|
||||
export type ProblemSetDifficulty = z.infer<typeof problemSetDifficultySchema>
|
||||
export type ProblemSetStatus = z.infer<typeof problemSetStatusSchema>
|
||||
export type BadgeConditionType = z.infer<typeof badgeConditionTypeSchema>
|
||||
export type AdminProblemSet = z.infer<typeof adminProblemSetSchema>
|
||||
export type AdminProblemSetList = z.infer<typeof adminProblemSetListSchema>
|
||||
export type CreateProblemSetRequest = z.infer<
|
||||
typeof createProblemSetRequestSchema
|
||||
>
|
||||
export type UpdateProblemSetRequest = z.infer<
|
||||
typeof updateProblemSetRequestSchema
|
||||
>
|
||||
export type UpdateProblemSetStatusRequest = z.infer<
|
||||
typeof updateProblemSetStatusRequestSchema
|
||||
>
|
||||
export type AdminProblemSetProblem = z.infer<
|
||||
typeof adminProblemSetProblemSchema
|
||||
>
|
||||
export type AddProblemToSetRequest = z.infer<
|
||||
typeof addProblemToSetRequestSchema
|
||||
>
|
||||
export type UpdateProblemInSetRequest = z.infer<
|
||||
typeof updateProblemInSetRequestSchema
|
||||
>
|
||||
export type CreateProblemSetRequest = z.infer<typeof createProblemSetRequestSchema>
|
||||
export type UpdateProblemSetRequest = z.infer<typeof updateProblemSetRequestSchema>
|
||||
export type UpdateProblemSetStatusRequest = z.infer<typeof updateProblemSetStatusRequestSchema>
|
||||
export type AdminProblemSetProblem = z.infer<typeof adminProblemSetProblemSchema>
|
||||
export type AddProblemToSetRequest = z.infer<typeof addProblemToSetRequestSchema>
|
||||
export type UpdateProblemInSetRequest = z.infer<typeof updateProblemInSetRequestSchema>
|
||||
export type AdminProblemSetBadge = z.infer<typeof adminProblemSetBadgeSchema>
|
||||
export type CreateProblemSetBadgeRequest = z.infer<
|
||||
typeof createProblemSetBadgeRequestSchema
|
||||
>
|
||||
export type UpdateProblemSetBadgeRequest = z.infer<
|
||||
typeof updateProblemSetBadgeRequestSchema
|
||||
>
|
||||
export type CreateProblemSetBadgeRequest = z.infer<typeof createProblemSetBadgeRequestSchema>
|
||||
export type UpdateProblemSetBadgeRequest = z.infer<typeof updateProblemSetBadgeRequestSchema>
|
||||
export type RenameTagRequest = z.infer<typeof renameTagRequestSchema>
|
||||
export type BatchProblemTagRequest = z.infer<
|
||||
typeof batchProblemTagRequestSchema
|
||||
>
|
||||
export type BatchProblemTagRequest = z.infer<typeof batchProblemTagRequestSchema>
|
||||
export type AcTrendYear = z.infer<typeof acTrendYearSchema>
|
||||
export type GenerateFlowchartRequest = z.infer<
|
||||
typeof generateFlowchartRequestSchema
|
||||
>
|
||||
export type GenerateFlowchartResponse = z.infer<
|
||||
typeof generateFlowchartResponseSchema
|
||||
>
|
||||
export type GenerateFlowchartRequest = z.infer<typeof generateFlowchartRequestSchema>
|
||||
export type GenerateFlowchartResponse = z.infer<typeof generateFlowchartResponseSchema>
|
||||
export type UpdateProblemRequest = z.infer<typeof updateProblemRequestSchema>
|
||||
export type MakeProblemPublicRequest = z.infer<
|
||||
typeof makeProblemPublicRequestSchema
|
||||
>
|
||||
export type AddContestProblemRequest = z.infer<
|
||||
typeof addContestProblemRequestSchema
|
||||
>
|
||||
export type MakeProblemPublicRequest = z.infer<typeof makeProblemPublicRequestSchema>
|
||||
export type AddContestProblemRequest = z.infer<typeof addContestProblemRequestSchema>
|
||||
export type TestCaseEntry = z.infer<typeof testCaseEntrySchema>
|
||||
export type UploadTestCaseResponse = z.infer<
|
||||
typeof uploadTestCaseResponseSchema
|
||||
>
|
||||
export type UploadTestCaseResponse = z.infer<typeof uploadTestCaseResponseSchema>
|
||||
export type SqlPreviewRequest = z.infer<typeof sqlPreviewRequestSchema>
|
||||
export type GenerateSqlTestCaseRequest = z.infer<
|
||||
typeof generateSqlTestCaseRequestSchema
|
||||
>
|
||||
export type GenerateSqlTestCaseRequest = z.infer<typeof generateSqlTestCaseRequestSchema>
|
||||
@@ -196,8 +196,7 @@ export const aiHintDoneSchema = z.object({
|
||||
export const HINT_ERROR_TAGS = {
|
||||
syntax: "语法错误",
|
||||
input_format: "输入读取方式不对(格式、分隔、个数)",
|
||||
output_format:
|
||||
"输出格式不对(多余的输入提示语、全角/半角符号、多余空格或换行、小数位数)",
|
||||
output_format: "输出格式不对(多余的输入提示语、全角/半角符号、多余空格或换行、小数位数)",
|
||||
condition: "条件判断写错(比较符、漏了分支)",
|
||||
loop_bound: "循环次数或边界不对(差一)",
|
||||
integer_division: "整数除法或取余用错",
|
||||
@@ -218,9 +217,7 @@ export type HintErrorTag = keyof typeof HINT_ERROR_TAGS
|
||||
* 这样注入最多能左右一个枚举值和两个行号。多出来的字段被 zod 剥掉。
|
||||
*/
|
||||
export const hintDiagnosisSchema = z.object({
|
||||
tag: z.enum(
|
||||
Object.keys(HINT_ERROR_TAGS) as [HintErrorTag, ...HintErrorTag[]],
|
||||
),
|
||||
tag: z.enum(Object.keys(HINT_ERROR_TAGS) as [HintErrorTag, ...HintErrorTag[]]),
|
||||
/** 问题所在的行号区间(从 1 起,含两端);说不准就是 null */
|
||||
lines: z.tuple([z.number().int().min(1), z.number().int().min(1)]).nullable(),
|
||||
confidence: z.enum(["high", "low"]),
|
||||
@@ -295,6 +292,4 @@ export type AiHintRequest = z.infer<typeof aiHintRequestSchema>
|
||||
export type AiHintDone = z.infer<typeof aiHintDoneSchema>
|
||||
export type AiHintFeedbackRequest = z.infer<typeof aiHintFeedbackRequestSchema>
|
||||
export type ClassAnalysisRequest = z.infer<typeof classAnalysisRequestSchema>
|
||||
export type ClassPkAnalysisRequest = z.infer<
|
||||
typeof classPkAnalysisRequestSchema
|
||||
>
|
||||
export type ClassPkAnalysisRequest = z.infer<typeof classPkAnalysisRequestSchema>
|
||||
@@ -66,11 +66,7 @@ export const classComparisonResponseSchema = z.object({
|
||||
export type ClassRankItem = z.infer<typeof classRankItemSchema>
|
||||
export type ClassUserRank = z.infer<typeof classUserRankSchema>
|
||||
export type ClassComparison = z.infer<typeof classComparisonSchema>
|
||||
export type ClassComparisonResponse = z.infer<
|
||||
typeof classComparisonResponseSchema
|
||||
>
|
||||
export type ClassComparisonResponse = z.infer<typeof classComparisonResponseSchema>
|
||||
|
||||
export type ClassUserRankItem = z.infer<typeof classUserRankItemSchema>
|
||||
export type ClassComparisonRequest = z.infer<
|
||||
typeof classComparisonRequestSchema
|
||||
>
|
||||
export type ClassComparisonRequest = z.infer<typeof classComparisonRequestSchema>
|
||||
@@ -24,9 +24,7 @@ export const announcementListItemSchema = announcementSchema.omit({
|
||||
content: true,
|
||||
})
|
||||
|
||||
export const announcementListSchema = paginatedSchema(
|
||||
announcementListItemSchema,
|
||||
)
|
||||
export const announcementListSchema = paginatedSchema(announcementListItemSchema)
|
||||
|
||||
export const messageSchema = z.object({
|
||||
id: z.number().int(),
|
||||
@@ -57,10 +55,7 @@ export const reactionKeySchema = z.enum([
|
||||
"want_explain",
|
||||
])
|
||||
|
||||
export const reactionCountsSchema = z.record(
|
||||
reactionKeySchema,
|
||||
z.number().int(),
|
||||
)
|
||||
export const reactionCountsSchema = z.record(reactionKeySchema, z.number().int())
|
||||
export const reactionStateSchema = z.object({
|
||||
mine: reactionKeySchema.nullable(),
|
||||
counts: reactionCountsSchema.nullable(),
|
||||
@@ -196,9 +191,7 @@ export type Tutorial = z.infer<typeof tutorialSchema>
|
||||
export type Exercise = z.infer<typeof exerciseSchema>
|
||||
export type TutorialProgress = z.infer<typeof tutorialProgressSchema>
|
||||
export type TutorialProgressPing = z.infer<typeof tutorialProgressPingSchema>
|
||||
export type ExerciseAttemptRequest = z.infer<
|
||||
typeof exerciseAttemptRequestSchema
|
||||
>
|
||||
export type ExerciseAttemptRequest = z.infer<typeof exerciseAttemptRequestSchema>
|
||||
|
||||
/**
|
||||
* 「已读」的门槛:累计停留满 3 分钟才算读过这一课。
|
||||
|
||||
@@ -27,9 +27,7 @@ export const contestPasswordRequestSchema = z.object({
|
||||
})
|
||||
|
||||
export const contestAccessSchema = z.object({ access: z.boolean() })
|
||||
export const contestProblemsSchema = z.array(
|
||||
z.union([problemListItemSchema, problemDetailSchema]),
|
||||
)
|
||||
export const contestProblemsSchema = z.array(z.union([problemListItemSchema, problemDetailSchema]))
|
||||
|
||||
/**
|
||||
* `acm_contest_rank.submission_info` 的 JSONB 原文。
|
||||
@@ -71,7 +69,5 @@ export type ContestAccess = z.infer<typeof contestAccessSchema>
|
||||
export type ContestSubmissionInfo = z.infer<typeof contestSubmissionInfoSchema>
|
||||
|
||||
export type ContestStatus = z.infer<typeof contestStatusSchema>
|
||||
export type ContestPasswordRequest = z.infer<
|
||||
typeof contestPasswordRequestSchema
|
||||
>
|
||||
export type ContestPasswordRequest = z.infer<typeof contestPasswordRequestSchema>
|
||||
export type ContestProblems = z.infer<typeof contestProblemsSchema>
|
||||
@@ -77,19 +77,12 @@ export const flowchartStatisticsSchema = z.object({
|
||||
totalCount: z.number().int(),
|
||||
avgScore: z.number(),
|
||||
gradeDistribution: z.record(z.string(), z.number().int()),
|
||||
criteriaAverages: z.record(
|
||||
z.string(),
|
||||
z.object({ avg: z.number(), max: z.number() }),
|
||||
),
|
||||
criteriaAverages: z.record(z.string(), z.object({ avg: z.number(), max: z.number() })),
|
||||
personCount: z.number().int(),
|
||||
completedCount: z.number().int(),
|
||||
wordFrequencies: z.array(
|
||||
z.object({ word: z.string(), count: z.number().int() }),
|
||||
),
|
||||
wordFrequencies: z.array(z.object({ word: z.string(), count: z.number().int() })),
|
||||
// 与提交统计共用「未完成学生」的形状,见 submission.ts 的 unacceptedStudentSchema
|
||||
dataUnaccepted: z.array(
|
||||
z.object({ username: z.string(), realName: z.string() }),
|
||||
),
|
||||
dataUnaccepted: z.array(z.object({ username: z.string(), realName: z.string() })),
|
||||
})
|
||||
|
||||
export const flowchartUpdateSchema = z.object({
|
||||
@@ -114,11 +107,7 @@ export type FlowchartListItem = z.infer<typeof flowchartListItemSchema>
|
||||
export type FlowchartList = z.infer<typeof flowchartListSchema>
|
||||
export type FlowchartCurrent = z.infer<typeof flowchartCurrentSchema>
|
||||
export type FlowchartDetail = z.infer<typeof flowchartDetailSchema>
|
||||
export type CreateFlowchartResponse = z.infer<
|
||||
typeof createFlowchartResponseSchema
|
||||
>
|
||||
export type CreateFlowchartRequest = z.infer<
|
||||
typeof createFlowchartRequestSchema
|
||||
>
|
||||
export type CreateFlowchartResponse = z.infer<typeof createFlowchartResponseSchema>
|
||||
export type CreateFlowchartRequest = z.infer<typeof createFlowchartRequestSchema>
|
||||
|
||||
export type FlowchartStatus = z.infer<typeof flowchartStatusSchema>
|
||||
@@ -22,14 +22,7 @@ import { z } from "zod"
|
||||
* 从别处冒出来(旧客户端的 localStorage、迁移之前排进队列的任务),走下面的
|
||||
* `normalizeLanguage()`,别直接 parse。
|
||||
*/
|
||||
export const judgeLanguageSchema = z.enum([
|
||||
"C",
|
||||
"C++",
|
||||
"Python",
|
||||
"Java",
|
||||
"JavaScript",
|
||||
"Golang",
|
||||
])
|
||||
export const judgeLanguageSchema = z.enum(["C", "C++", "Python", "Java", "JavaScript", "Golang"])
|
||||
|
||||
/**
|
||||
* 题目可以挂的语言 = 沙箱语言 + 两种非沙箱题型。
|
||||
@@ -42,11 +35,7 @@ export const judgeLanguageSchema = z.enum([
|
||||
* 于是那 91 条提交的 `language` 在类型上是 `undefined` —— 这就是两份真相
|
||||
* 各自演进的代价,现在并成一份。
|
||||
*/
|
||||
export const problemLanguageSchema = z.enum([
|
||||
...judgeLanguageSchema.options,
|
||||
"SQL",
|
||||
"Flowchart",
|
||||
])
|
||||
export const problemLanguageSchema = z.enum([...judgeLanguageSchema.options, "SQL", "Flowchart"])
|
||||
|
||||
export type JudgeLanguage = z.infer<typeof judgeLanguageSchema>
|
||||
export type ProblemLanguage = z.infer<typeof problemLanguageSchema>
|
||||
@@ -68,8 +57,6 @@ const LANGUAGE_ALIASES: Record<string, ProblemLanguage> = {
|
||||
/** 把可能是旧值的语言名归一化;认不出来返回 null,由调用方决定怎么兜底。 */
|
||||
export function normalizeLanguage(value: unknown): ProblemLanguage | null {
|
||||
if (typeof value !== "string") return null
|
||||
const parsed = problemLanguageSchema.safeParse(
|
||||
LANGUAGE_ALIASES[value] ?? value,
|
||||
)
|
||||
const parsed = problemLanguageSchema.safeParse(LANGUAGE_ALIASES[value] ?? value)
|
||||
return parsed.success ? parsed.data : null
|
||||
}
|
||||
@@ -148,10 +148,7 @@ const C_NODE_TARGETS = {
|
||||
include: { label: "#include 指令", node: "preproc_include" },
|
||||
} satisfies Record<string, AstNodeTarget>
|
||||
|
||||
export const AST_NODE_TARGETS_BY_LANGUAGE: Record<
|
||||
string,
|
||||
Record<string, AstNodeTarget>
|
||||
> = {
|
||||
export const AST_NODE_TARGETS_BY_LANGUAGE: Record<string, Record<string, AstNodeTarget>> = {
|
||||
C: C_NODE_TARGETS,
|
||||
/**
|
||||
* tree-sitter-cpp 继承 tree-sitter-c 的语法,C 那 14 条在 C++ 树里逐个实测通用,
|
||||
@@ -253,10 +250,7 @@ const C_OPERATOR_TARGETS = {
|
||||
"|": "|",
|
||||
}
|
||||
|
||||
export const AST_OPERATOR_TARGETS_BY_LANGUAGE: Record<
|
||||
string,
|
||||
Record<string, string>
|
||||
> = {
|
||||
export const AST_OPERATOR_TARGETS_BY_LANGUAGE: Record<string, Record<string, string>> = {
|
||||
C: C_OPERATOR_TARGETS,
|
||||
// `<<` / `>>` 对 C++ 主要是 cout/cin 的流运算符(位移是同一个 token)
|
||||
"C++": { ...C_OPERATOR_TARGETS, "<<": "<<", ">>": ">>" },
|
||||
@@ -295,12 +289,11 @@ export const AST_OPERATOR_TARGETS_BY_LANGUAGE: Record<
|
||||
export const AST_SUPPORTED_LANGUAGES = Object.keys(AST_NODE_TARGETS_BY_LANGUAGE)
|
||||
|
||||
/** 全语言的节点中文名并集,只给拿不到语言的场合做回落。有语言一律走 astNodeLabel() */
|
||||
export const AST_NODE_TARGET_LABELS: Record<string, string> =
|
||||
Object.fromEntries(
|
||||
Object.values(AST_NODE_TARGETS_BY_LANGUAGE).flatMap((table) =>
|
||||
Object.entries(table).map(([target, entry]) => [target, entry.label]),
|
||||
),
|
||||
)
|
||||
export const AST_NODE_TARGET_LABELS: Record<string, string> = Object.fromEntries(
|
||||
Object.values(AST_NODE_TARGETS_BY_LANGUAGE).flatMap((table) =>
|
||||
Object.entries(table).map(([target, entry]) => [target, entry.label]),
|
||||
),
|
||||
)
|
||||
|
||||
export function astNodeLabel(target: string, language?: string): string {
|
||||
const table = language ? AST_NODE_TARGETS_BY_LANGUAGE[language] : undefined
|
||||
@@ -321,11 +314,7 @@ export function astTargetNodeType(target: string, language: string): string {
|
||||
}
|
||||
|
||||
export function astOperatorLabel(target: string, language?: string): string {
|
||||
return (
|
||||
(language
|
||||
? AST_OPERATOR_TARGETS_BY_LANGUAGE[language]?.[target]
|
||||
: undefined) ?? target
|
||||
)
|
||||
return (language ? AST_OPERATOR_TARGETS_BY_LANGUAGE[language]?.[target] : undefined) ?? target
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -343,9 +332,7 @@ export function astRuleIsMeaningful(rule: {
|
||||
max?: number
|
||||
}): boolean {
|
||||
if (!rule.engine.startsWith("count")) return true
|
||||
return (
|
||||
rule.exact !== undefined || rule.min !== undefined || rule.max !== undefined
|
||||
)
|
||||
return rule.exact !== undefined || rule.min !== undefined || rule.max !== undefined
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -364,10 +351,7 @@ export const astRequirementSchema = z.object({
|
||||
})
|
||||
|
||||
/** 按语言分组,与 astRulesSchema 同一套键 */
|
||||
export const astRequirementsSchema = z.record(
|
||||
z.string(),
|
||||
z.array(astRequirementSchema),
|
||||
)
|
||||
export const astRequirementsSchema = z.record(z.string(), z.array(astRequirementSchema))
|
||||
|
||||
export const problemDetailSchema = z.object({
|
||||
id: z.number().int(),
|
||||
|
||||
@@ -91,9 +91,7 @@ export const problemSetProgressSchema = z.object({
|
||||
completedProblems: z.array(completedProblemSchema),
|
||||
})
|
||||
|
||||
export const problemSetProgressListSchema = paginatedSchema(
|
||||
problemSetProgressSchema,
|
||||
).extend({
|
||||
export const problemSetProgressListSchema = paginatedSchema(problemSetProgressSchema).extend({
|
||||
statistics: z.object({
|
||||
total: z.number().int(),
|
||||
completed: z.number().int(),
|
||||
@@ -115,13 +113,9 @@ export type ProblemSetList = z.infer<typeof problemSetListSchema>
|
||||
export type ProblemSetBadge = z.infer<typeof problemSetBadgeSchema>
|
||||
export type ProblemSetProblem = z.infer<typeof problemSetProblemSchema>
|
||||
export type ProblemSetProgress = z.infer<typeof problemSetProgressSchema>
|
||||
export type ProblemSetProgressList = z.infer<
|
||||
typeof problemSetProgressListSchema
|
||||
>
|
||||
export type ProblemSetProgressList = z.infer<typeof problemSetProgressListSchema>
|
||||
export type UserBadge = z.infer<typeof userBadgeSchema>
|
||||
export type CompletedProblem = z.infer<typeof completedProblemSchema>
|
||||
|
||||
export type ProblemSetUserProgressSummary = z.infer<
|
||||
typeof problemSetUserProgressSummarySchema
|
||||
>
|
||||
export type ProblemSetUserProgressSummary = z.infer<typeof problemSetUserProgressSummarySchema>
|
||||
export type JoinProblemSetRequest = z.infer<typeof joinProblemSetRequestSchema>
|
||||
@@ -32,35 +32,23 @@ export type ProblemPermission = (typeof PROBLEM_PERMISSIONS)[number]
|
||||
*/
|
||||
|
||||
/** 能进后台的三种 */
|
||||
export const ADMIN_ROLES: readonly AdminType[] = [
|
||||
"Student Admin",
|
||||
"Teacher Admin",
|
||||
"Super Admin",
|
||||
]
|
||||
export const ADMIN_ROLES: readonly AdminType[] = ["Student Admin", "Teacher Admin", "Super Admin"]
|
||||
|
||||
/** 老师及以上 */
|
||||
export const TEACHER_ROLES: readonly AdminType[] = [
|
||||
"Teacher Admin",
|
||||
"Super Admin",
|
||||
]
|
||||
export const TEACHER_ROLES: readonly AdminType[] = ["Teacher Admin", "Super Admin"]
|
||||
|
||||
/**
|
||||
* 学生口径:排行榜、班级榜、比赛榜、自学统计都只算这两种,教师和超管不入榜。
|
||||
* 注意 Student Admin 算学生 —— 他要参赛、要上榜,只是多了个后台入口。
|
||||
*/
|
||||
export const STUDENT_ROLES: readonly AdminType[] = [
|
||||
"Regular User",
|
||||
"Student Admin",
|
||||
]
|
||||
export const STUDENT_ROLES: readonly AdminType[] = ["Regular User", "Student Admin"]
|
||||
|
||||
/**
|
||||
* 把库里读出来的裸字符串收成联合类型。**认不出来的一律降成最低权限**,
|
||||
* 不抛错:脏数据不该让人登不上,但更不该让人凭一个拼错的角色名拿到权限。
|
||||
*/
|
||||
export function toAdminType(value: string): AdminType {
|
||||
return (ADMIN_TYPES as readonly string[]).includes(value)
|
||||
? (value as AdminType)
|
||||
: "Regular User"
|
||||
return (ADMIN_TYPES as readonly string[]).includes(value) ? (value as AdminType) : "Regular User"
|
||||
}
|
||||
|
||||
export function toProblemPermission(value: string): ProblemPermission {
|
||||
|
||||
@@ -16,10 +16,7 @@ export const onlineCountSchema = z.object({
|
||||
count: z.number().int().nonnegative(),
|
||||
})
|
||||
|
||||
export const quoteSchema = z.union([
|
||||
z.string(),
|
||||
z.record(z.string(), z.unknown()),
|
||||
])
|
||||
export const quoteSchema = z.union([z.string(), z.record(z.string(), z.unknown())])
|
||||
|
||||
export type WebsiteConfig = z.infer<typeof websiteConfigSchema>
|
||||
export type Quote = z.infer<typeof quoteSchema>
|
||||
|
||||
@@ -386,13 +386,9 @@ export const todaySubmissionStatisticsSchema = z.object({
|
||||
/** 按东八区钟点分的 24 个桶,**下标就是钟点**,没有提交的钟点是 0 */
|
||||
hours: z.array(z.number().int()).length(24),
|
||||
/** 按语言,提交数倒序。零提交的语言不在表里 */
|
||||
languages: z.array(
|
||||
z.object({ language: problemLanguageSchema, count: z.number().int() }),
|
||||
),
|
||||
languages: z.array(z.object({ language: problemLanguageSchema, count: z.number().int() })),
|
||||
/** 按判题结果,条数倒序 */
|
||||
results: z.array(
|
||||
z.object({ result: judgeStatusSchema, count: z.number().int() }),
|
||||
),
|
||||
results: z.array(z.object({ result: judgeStatusSchema, count: z.number().int() })),
|
||||
/**
|
||||
* 今天最热的几道题,提交数倒序,最多 10 道。
|
||||
* **只含公开可见的题目** —— 这个接口不需要登录,不能拿它探未发布题目的标题。
|
||||
@@ -416,30 +412,20 @@ export const formatCodeResponseSchema = z.object({ code: z.string() })
|
||||
|
||||
export type StatisticInfo = z.infer<typeof statisticInfoSchema>
|
||||
export type SubmissionTrace = z.infer<typeof submissionTraceSchema>
|
||||
export type CreateSubmissionRequest = z.infer<
|
||||
typeof createSubmissionRequestSchema
|
||||
>
|
||||
export type CreateSubmissionRequest = z.infer<typeof createSubmissionRequestSchema>
|
||||
export type SubmissionDetail = z.infer<typeof submissionDetailSchema>
|
||||
export type SubmissionUpdate = z.infer<typeof submissionUpdateSchema>
|
||||
export type SubmissionStatistics = z.infer<typeof submissionStatisticsSchema>
|
||||
export type TodaySubmissionStatistics = z.infer<
|
||||
typeof todaySubmissionStatisticsSchema
|
||||
>
|
||||
export type SubmissionStatisticsUser = z.infer<
|
||||
typeof submissionStatisticsUserSchema
|
||||
>
|
||||
export type SubmissionStatisticsItems = z.infer<
|
||||
typeof submissionStatisticsItemsSchema
|
||||
>
|
||||
export type TodaySubmissionStatistics = z.infer<typeof todaySubmissionStatisticsSchema>
|
||||
export type SubmissionStatisticsUser = z.infer<typeof submissionStatisticsUserSchema>
|
||||
export type SubmissionStatisticsItems = z.infer<typeof submissionStatisticsItemsSchema>
|
||||
export type UnacceptedStudent = z.infer<typeof unacceptedStudentSchema>
|
||||
export type AttemptedStudent = z.infer<typeof attemptedStudentSchema>
|
||||
|
||||
export type SubmissionListItem = z.infer<typeof submissionListItemSchema>
|
||||
export type SubmissionList = z.infer<typeof submissionListSchema>
|
||||
export type EmbeddedSubmission = z.infer<typeof embeddedSubmissionSchema>
|
||||
export type CreateSubmissionResponse = z.infer<
|
||||
typeof createSubmissionResponseSchema
|
||||
>
|
||||
export type CreateSubmissionResponse = z.infer<typeof createSubmissionResponseSchema>
|
||||
export type FormatCodeResponse = z.infer<typeof formatCodeResponseSchema>
|
||||
|
||||
export type FormatCodeRequest = z.infer<typeof formatCodeRequestSchema>
|
||||
Reference in new issue
Block a user