fix: unify panic room code format and validate room join id
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user