feat(阶段3): oj 侧端点铺开(基线提交,未经评审)
由外部 agent (Codex) 在本会话额度中断期间完成。原样提交作为基线, 后续修复单独成 commit,便于区分与回退。 覆盖 oj 侧 65 个端点,新增 9 组路由(account/achievement/ai/classroom/ content/contest/flowchart/problemset/site)与对应 Zod 契约。 已核验:tsc --noEmit 退出码 0;API 可启动;/api/problems 返回真实数据; judge 与 flowchart worker 均 ready。 未核验:权限边界与数据泄露,评审进行中。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
47
apps/api/src/routes/site.ts
Normal file
47
apps/api/src/routes/site.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { quoteSchema, websiteConfigSchema } from "@oj2/contract"
|
||||
import { asc, desc, eq } from "drizzle-orm"
|
||||
import { Hono } from "hono"
|
||||
|
||||
import { db, schema } from "../db"
|
||||
import { failure, success } from "../http"
|
||||
import { getWebsiteOptions } from "../services/options"
|
||||
|
||||
export const siteRoutes = new Hono()
|
||||
|
||||
siteRoutes.get("/site", async (c) => {
|
||||
const options = await getWebsiteOptions()
|
||||
return success(c, websiteConfigSchema.parse({
|
||||
websiteBaseUrl: options.website_base_url,
|
||||
websiteName: options.website_name,
|
||||
websiteNameShortcut: options.website_name_shortcut,
|
||||
websiteFooter: options.website_footer,
|
||||
allowRegister: options.allow_register,
|
||||
submissionListShowAll: options.submission_list_show_all,
|
||||
classList: options.class_list,
|
||||
enableMaxkb: options.enable_maxkb,
|
||||
}))
|
||||
})
|
||||
|
||||
const quotes = [
|
||||
{ hitokoto: "程序首先是写给人读的,其次才是让机器执行。", from: "Structure and Interpretation of Computer Programs" },
|
||||
{ hitokoto: "把大问题拆成足够小的问题,答案就会浮现。", from: "判题狗" },
|
||||
{ hitokoto: "一次没通过,只是多得到了一条线索。", from: "判题狗" },
|
||||
]
|
||||
|
||||
siteRoutes.get("/quotes/random", (c) => {
|
||||
const item = quotes[Math.floor(Math.random() * quotes.length)] ?? quotes[0]
|
||||
return success(c, quoteSchema.parse(item))
|
||||
})
|
||||
|
||||
siteRoutes.get("/classes/:className/usernames", async (c) => {
|
||||
const className = c.req.param("className").trim()
|
||||
if (!/^\d{3,4}$/.test(className)) {
|
||||
return failure(c, 400, "invalid-class", "Class name must contain 3 or 4 digits")
|
||||
}
|
||||
const rows = await db
|
||||
.select({ username: schema.user.username })
|
||||
.from(schema.user)
|
||||
.where(eq(schema.user.className, className))
|
||||
.orderBy(desc(schema.user.createTime), asc(schema.user.id))
|
||||
return success(c, rows.map(({ username }) => username.replace(`ks${className}`, "")))
|
||||
})
|
||||
Reference in New Issue
Block a user