's'
This commit is contained in:
40
app/api/join/volunteers/route.ts
Normal file
40
app/api/join/volunteers/route.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user