41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { getAdminToken } from "@/app/lib/pocketbase/admin";
|
|
import { getPocketBaseConfig } from "@/config/services.config";
|
|
|
|
/** 获取志愿者列表 - solanRed 中 is_volunteer=true 的记录 */
|
|
export async function GET() {
|
|
const token = await getAdminToken();
|
|
if (!token) {
|
|
return NextResponse.json({ ok: true, volunteers: [] }, { status: 200 });
|
|
}
|
|
|
|
const pb = getPocketBaseConfig();
|
|
const base = pb.url.replace(/\/$/, "");
|
|
|
|
try {
|
|
const filter = encodeURIComponent('is_volunteer=true');
|
|
const res = await fetch(
|
|
`${base}/api/collections/${pb.joinCollection}/records?filter=${filter}&sort=-created&perPage=20`,
|
|
{
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
cache: "no-store",
|
|
}
|
|
);
|
|
if (!res.ok) {
|
|
return NextResponse.json({ ok: true, volunteers: [] }, { status: 200 });
|
|
}
|
|
const data = await res.json();
|
|
const items = Array.isArray(data?.items) ? data.items : [];
|
|
const volunteers = items.map(
|
|
(r: { nickname?: string; xiaohongshu_nickname?: string; media?: string; xiaohongshu_url?: string }) => ({
|
|
nickname: String(r?.xiaohongshu_nickname || r?.nickname || "").trim() || "志愿者",
|
|
avatar: String(r?.media || "").trim() || undefined,
|
|
xiaohongshu_url: String(r?.xiaohongshu_url || "").trim() || undefined,
|
|
})
|
|
);
|
|
return NextResponse.json({ ok: true, volunteers });
|
|
} catch {
|
|
return NextResponse.json({ ok: true, volunteers: [] }, { status: 200 });
|
|
}
|
|
}
|