This commit is contained in:
eric
2026-03-16 09:32:35 -05:00
parent c54c236d1b
commit 14b0cd2429
21 changed files with 1058 additions and 706 deletions

21
app/lib/volunteers.ts Normal file
View File

@@ -0,0 +1,21 @@
import { headers } from "next/headers";
/** 服务端获取第一个志愿者,用于替换发起人志愿者卡片。调用内部 API(API 优先走 salonapi 后端) */
export async function getVolunteer(): Promise<{
nickname: string;
avatar?: string;
xiaohongshu_url?: string;
} | null> {
try {
const headersList = await headers();
const host = headersList.get("host") || headersList.get("x-forwarded-host") || "localhost:3002";
const proto = headersList.get("x-forwarded-proto") || (host.includes("localhost") ? "http" : "https");
const base = `${proto}://${host}`;
const res = await fetch(`${base}/api/join/volunteers`, { cache: "no-store" });
const data = await res.json();
const v = data?.volunteer;
return v && typeof v === "object" && v.nickname ? v : null;
} catch {
return null;
}
}