This commit is contained in:
eric
2026-03-16 01:09:13 -05:00
parent 91d56fa086
commit ff135563fb
15 changed files with 532 additions and 143 deletions

View File

@@ -29,6 +29,7 @@ export async function POST(request: NextRequest) {
const session = String(formData.session || "").trim();
const ageRange = String(formData.age_range || "").trim();
const wechatOrPhone = String(formData.wechat_or_phone || "").trim();
const xiaohongshuUrl = String(formData.xiaohongshu_url || "").trim();
let intro = String(formData.intro || "").trim();
const firstTime = String(formData.first_time || "").trim();
const agreeRules = !!formData.agree_rules;
@@ -42,9 +43,9 @@ export async function POST(request: NextRequest) {
intro = extra;
}
if (!nickname || !wechatOrPhone || !intro || !session || !agreeRules) {
if (!nickname || !wechatOrPhone || !intro || !session || !agreeRules || !xiaohongshuUrl) {
return NextResponse.json(
{ ok: false, error: "请填写必填项" },
{ ok: false, error: "请填写必填项(含小红书主页地址)" },
{ status: 400 }
);
}
@@ -57,6 +58,7 @@ export async function POST(request: NextRequest) {
occupation: city,
reason: intro,
wechatId: wechatOrPhone,
xiaohongshu_url: xiaohongshuUrl,
gender: "",
education: "",
gradYear: "",
@@ -114,11 +116,13 @@ async function tryPocketBaseDirect(
const base = pb.url.replace(/\/$/, "");
const url = `${base}/api/collections/${pb.joinCollection}/records`;
const reasonParts = [record.reason, record.age_range, record.first_time];
if (record.xiaohongshu_url) reasonParts.push(`小红书:${record.xiaohongshu_url}`);
const body: Record<string, unknown> = {
user_id: record.user_id,
nickname: record.nickname,
occupation: record.occupation ?? "",
reason: [record.reason, record.age_range, record.first_time].filter(Boolean).join(" | "),
reason: reasonParts.filter(Boolean).join(" | "),
wechatId: record.wechatId ?? "",
gender: record.gender ?? "",
education: record.education ?? "",

View File

@@ -0,0 +1,60 @@
import { NextRequest, NextResponse } from "next/server";
import { getAdminToken } from "@/app/lib/pocketbase/admin";
import { getPocketBaseConfig } from "@/config/services.config";
import { SESSIONS } from "@/config/home.config";
/** 按场次返回报名人数和最近报名者(昵称),头像由前端用 initials 或占位 */
export async function GET(request: NextRequest) {
const token = await getAdminToken();
if (!token) {
return NextResponse.json(
{ ok: true, stats: getEmptyStats() },
{ status: 200 }
);
}
const pb = getPocketBaseConfig();
const base = pb.url.replace(/\/$/, "");
const stats: Record<string, { count: number; joiners: { nickname: string; avatar?: string; xiaohongshu_url?: string }[] }> = {};
for (const s of SESSIONS) {
try {
const filter = encodeURIComponent(`type="${s.id}"`);
const res = await fetch(
`${base}/api/collections/${pb.joinCollection}/records?filter=${filter}&sort=-created&perPage=6`,
{
headers: { Authorization: `Bearer ${token}` },
cache: "no-store",
}
);
if (!res.ok) {
stats[s.id] = { count: 0, joiners: [] };
continue;
}
const data = await res.json();
const items = Array.isArray(data?.items) ? data.items : [];
const total = typeof data?.totalItems === "number" ? data.totalItems : items.length;
stats[s.id] = {
count: total,
joiners: items.slice(0, 6).map((r: { nickname?: string; xiaohongshu_nickname?: string; xiaohongshu_avatar?: string; xiaohongshu_url?: string }) => ({
nickname: String(r?.xiaohongshu_nickname || r?.nickname || "").trim() || "匿名",
avatar: String(r?.xiaohongshu_avatar || "").trim() || undefined,
xiaohongshu_url: String(r?.xiaohongshu_url || "").trim() || undefined,
})),
};
} catch {
stats[s.id] = { count: 0, joiners: [] };
}
}
return NextResponse.json({ ok: true, stats });
}
function getEmptyStats() {
const stats: Record<string, { count: number; joiners: { nickname: string; avatar?: string; xiaohongshu_url?: string }[] }> = {};
for (const s of SESSIONS) {
stats[s.id] = { count: 0, joiners: [] };
}
return stats;
}