fix: unify panic room code format and validate room join id

This commit is contained in:
2026-03-03 12:04:00 +08:00
parent 4f4220652e
commit f3d8a58603
7 changed files with 277 additions and 15 deletions
+13
View File
@@ -48,3 +48,16 @@ export function requireString(value: unknown, fieldName: string): string {
}
return value;
}
const PANIC_ROOM_ID_REGEX = /^[A-Z0-9]{6}$/;
export function validatePanicRoomId(raw: unknown): string {
if (!raw || typeof raw !== "string") {
throw new ApiError("roomId 不能为空");
}
const roomId = raw.trim().toUpperCase();
if (!PANIC_ROOM_ID_REGEX.test(roomId)) {
throw new ApiError("房间号格式无效,应为 6 位字母数字", 400);
}
return roomId;
}