Files
2026-03-16 09:32:35 -05:00

22 lines
846 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { headers } from "next/headers";
/** 服务端获取第一个志愿者,用于替换发起人志愿者卡片。调用内部 APIAPI 优先走 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;
}
}