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

View File

@@ -1,19 +1,33 @@
import { NextResponse } from "next/server";
import { NextRequest, NextResponse } from "next/server";
import { getAdminToken } from "@/app/lib/pocketbase/admin";
import { getPocketBaseConfig } from "@/config/services.config";
import { getSalonApi } from "@/app/lib/salonApi";
/** 获取志愿者列表 - 优先 salonapi,回退直连 PocketBase */
export async function GET(request: NextRequest) {
try {
const { status, data } = await getSalonApi(request, "/api/salon/join/volunteers", {
timeoutMs: 8000,
});
if (status === 200 && data && typeof data === "object") {
const v = (data as { volunteer?: unknown }).volunteer;
const payload = v && typeof v === "object" ? { volunteer: v } : { volunteer: null };
return NextResponse.json(payload);
}
} catch {
// salonapi 不可用,回退直连 PocketBase
}
/** 获取志愿者列表 - solanRed 中 is_volunteer=true 的记录 */
export async function GET() {
const token = await getAdminToken();
if (!token) {
return NextResponse.json({ ok: true, volunteers: [] }, { status: 200 });
return NextResponse.json({ ok: true, volunteer: null }, { status: 200 });
}
const pb = getPocketBaseConfig();
const base = pb.url.replace(/\/$/, "");
try {
const filter = encodeURIComponent('is_volunteer=true && is_approved=true');
const filter = encodeURIComponent("is_volunteer = true && is_approved = true");
const res = await fetch(
`${base}/api/collections/${pb.joinCollection}/records?filter=${filter}&sort=-created&perPage=20`,
{
@@ -22,19 +36,20 @@ export async function GET() {
}
);
if (!res.ok) {
return NextResponse.json({ ok: true, volunteers: [] }, { status: 200 });
return NextResponse.json({ ok: true, volunteer: null }, { 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 });
const rec = items[0] ?? null;
const volunteer = rec
? {
nickname: String(rec?.xiaohongshu_nickname || rec?.nickname || "").trim() || "志愿者",
avatar: String(rec?.media || "").trim() || undefined,
xiaohongshu_url: String(rec?.xiaohongshu_url || "").trim() || undefined,
}
: null;
return NextResponse.json({ ok: true, volunteer });
} catch {
return NextResponse.json({ ok: true, volunteers: [] }, { status: 200 });
return NextResponse.json({ ok: true, volunteer: null }, { status: 200 });
}
}