feat: 盲盒房间体系重构 — 强制登录、独立房间、用户归属

- 新增 BlindBoxRoom/BlindBoxMember 模型,BlindBoxIdea 增加 userId/drawnById
- 新增房间 API(创建/加入/列表/详情),所有盲盒 API 增加认证和成员校验
- 新建盲盒大厅页面(三层引导式设计:未登录氛围页/首次创建引导/房间列表)
- 新建盲盒房间页面(成员校验/邀请分享/用户归属展示/自动聚焦)
- 首页删除契约画廊和 localStorage 盲盒逻辑,周末契约跳转到 /blindbox
- 清理旧路由 /room/[id]/blindbox
- 提取共享工具 src/lib/blindbox.ts(错误响应/房间号生成/成员校验)
- AuthModal 支持 defaultTab 参数
- 更新项目规范:新项目原则、代码优雅和复用优先
This commit is contained in:
2026-02-26 12:25:32 +08:00
parent 11d872e72a
commit 14b0aaece4
15 changed files with 1502 additions and 557 deletions
+43
View File
@@ -0,0 +1,43 @@
import { prisma } from "@/lib/prisma";
import { NextResponse } from "next/server";
export function errorResponse(message: string, status: number) {
return NextResponse.json({ error: message }, { status });
}
export function generateRoomCode(): string {
const chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
let code = "";
for (let i = 0; i < 6; i++) {
code += chars[Math.floor(Math.random() * chars.length)];
}
return code;
}
export async function generateUniqueRoomCode(): Promise<string> {
for (let attempt = 0; attempt < 10; attempt++) {
const code = generateRoomCode();
const existing = await prisma.blindBoxRoom.findUnique({ where: { code } });
if (!existing) return code;
}
throw new Error("无法生成唯一房间号");
}
export async function validateMembership(roomId: string, userId: string) {
const member = await prisma.blindBoxMember.findUnique({
where: { roomId_userId: { roomId, userId } },
});
return !!member;
}
export async function getRoomByCode(code: string) {
return prisma.blindBoxRoom.findUnique({
where: { code },
include: {
members: {
include: { user: { select: { id: true, username: true, avatar: true } } },
},
_count: { select: { ideas: { where: { status: "in_pool" } } } },
},
});
}