- Add 11 missing server action files: badges, bulk-users, catalog, catalog-bc, catalog-items, import-badges, import-furni, multi-account-detect, permissions, rooms, soundtracks - Add missing admin navigation links: tickets, sounds, translations, import, radio sub-pages - Add translation keys for all new navigation items
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { apiJson, pagination } from "@/lib/api";
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
/**
|
|
* GET /api/articles — paginated list of website_articles, newest first.
|
|
* Mirrors the /news page query (prisma.websiteArticles). Returns list cards
|
|
* (shortStory only, never fullStory) plus pagination metadata.
|
|
*/
|
|
export async function GET(req: Request) {
|
|
const sp = new URL(req.url).searchParams;
|
|
const { page, perPage, skip, take } = pagination(sp);
|
|
|
|
try {
|
|
const [total, articles] = await Promise.all([
|
|
prisma.websiteArticles.count(),
|
|
prisma.websiteArticles.findMany({
|
|
select: {
|
|
id: true,
|
|
title: true,
|
|
slug: true,
|
|
shortStory: true,
|
|
image: true,
|
|
createdAt: true,
|
|
},
|
|
orderBy: { createdAt: "desc" },
|
|
skip,
|
|
take,
|
|
}),
|
|
]);
|
|
|
|
return apiJson({
|
|
data: articles,
|
|
meta: {
|
|
page,
|
|
perPage,
|
|
total,
|
|
lastPage: Math.max(1, Math.ceil(total / perPage)),
|
|
},
|
|
});
|
|
} catch {
|
|
// DB unavailable — return an empty payload instead of a 500.
|
|
return apiJson({ data: [], meta: { page, perPage, total: 0, lastPage: 1 } }, { status: 200 });
|
|
}
|
|
}
|