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
@@ -161,7 +161,7 @@ export type SessionResult =
|
||||
| { user: AuthUser; reason?: undefined }
|
||||
| { user: null; reason: "anonymous" | "disabled" }
|
||||
|
||||
async function getUserByToken(
|
||||
async function authenticateToken(
|
||||
token: string | undefined,
|
||||
): Promise<SessionResult> {
|
||||
if (!token) return { user: null, reason: "anonymous" }
|
||||
@@ -228,7 +228,7 @@ async function getUserByToken(
|
||||
|
||||
/** 要区分「未登录」和「已被禁用」的用这个 —— 目前只有鉴权中间件需要 */
|
||||
export function resolveSession(c: Context) {
|
||||
return getUserByToken(getCookie(c, config.sessionCookie))
|
||||
return authenticateToken(getCookie(c, config.sessionCookie))
|
||||
}
|
||||
|
||||
/** 只关心「是谁」的调用方用这个 */
|
||||
@@ -237,7 +237,8 @@ export async function getSessionUser(c: Context) {
|
||||
}
|
||||
|
||||
export async function getRequestSessionUser(request: Request) {
|
||||
return (await getUserByToken(readCookie(request, config.sessionCookie))).user
|
||||
return (await authenticateToken(readCookie(request, config.sessionCookie)))
|
||||
.user
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -254,11 +255,11 @@ export function readRequestSessionToken(request: Request) {
|
||||
* 用 EXPIRE 同时完成「判断存在」和「续期」,比 GET + EXPIRE 少一趟往返;两条 EXPIRE
|
||||
* 走一次 pipeline,仍然只有一趟。
|
||||
*
|
||||
* 续期这件事本身是要的:HTTP 请求会走 getUserByToken 里的 redis.expire 续期,
|
||||
* 续期这件事本身是要的:HTTP 请求会走 authenticateToken 里的 redis.expire 续期,
|
||||
* 而只开着页面挂 WebSocket 的人一次请求都不发,不该因此被算成不活跃踢下线。
|
||||
*
|
||||
* **反向索引必须跟着一起续。** 走到这里的正是那种一次 HTTP 请求都不发的连接,
|
||||
* 它碰不到 getUserByToken 里那两条并排的 expire。只续会话不续索引的话,索引先到期、
|
||||
* 它碰不到 authenticateToken 里那两条并排的 expire。只续会话不续索引的话,索引先到期、
|
||||
* 会话却被巡检一直续着,之后改密码 / 禁用账号走 revokeUserSessions 就 SMEMBERS
|
||||
* 不到这张 token —— WebSocket 那边还有 publishSessionRevoked 按 userId 兜底能断掉,
|
||||
* 但 HTTP 一侧拿着那张 cookie 照用不误,而改密码要的恰恰是让 HTTP 立刻失效。
|
||||
|
||||
Reference in new issue
Block a user