first commit

This commit is contained in:
luoyangwei
2026-06-06 00:49:07 +08:00
commit 2b860d201e
134 changed files with 22773 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
import { getOptionalAppUserFromRequest } from "@/server/app/app-auth";
import { listPublishedCollections } from "@/server/site/photo-collections";
import { NextResponse, type NextRequest } from "next/server";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url);
const page = parseInt(searchParams.get("page") || "1", 10);
const pageSize = parseInt(
searchParams.get("pageSize") ||
searchParams.get("page_size") ||
"20",
10,
);
if (page < 1 || pageSize < 1 || pageSize > 50) {
return NextResponse.json(
{ ok: false, error: "Invalid pagination parameters." },
{ status: 400 },
);
}
const user = await getOptionalAppUserFromRequest(request);
const result = await listPublishedCollections({
page,
pageSize,
userId: user?.id ?? null,
});
return NextResponse.json({
ok: true,
data: result.data,
pagination: {
page,
pageSize,
total: result.total,
hasMore: result.total > page * pageSize,
nextPage: result.total > page * pageSize ? page + 1 : null,
},
});
} catch (error) {
const message =
error instanceof Error ? error.message : "Unknown error.";
return NextResponse.json(
{ ok: false, error: message },
{ status: 500 },
);
}
}