- Clone import: defer FurnitureData.json writes and append all entries in a single batched write instead of one read-modify-write per item, removing the main serialization bottleneck for large batches. - Clone import: raise SSE batch concurrency cap from 5 to 10 and bump the clone client/route default from 2 to 6. - Add a flush hook to runSseBatch so callers can batch deferred work before batch_complete is emitted, and surface flush errors as an error event. - Enable Next.js Cache Components (instant: false opt-out) and silence the related build warnings in next.config.ts. - Switch isomorphic-dompurify to dompurify and refresh dependencies.
65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
// Public REST: rare furni trade values (website_rare_values).
|
|
// AtomCMS JSON API parity — read-only catalog of rares with their credit /
|
|
// currency values. Supports ?category=<id> filter; paginated, ordered by name.
|
|
import { asc, count, eq } from "drizzle-orm";
|
|
import { apiError, apiJson, pagination, positiveBigInt } from "@/lib/api";
|
|
import { db, WebsiteRareValues } from "@/lib/db";
|
|
|
|
export async function GET(req: Request) {
|
|
const sp = new URL(req.url).searchParams;
|
|
const { page, perPage, skip, take } = pagination(sp);
|
|
|
|
// Optional ?category=<id> filter (category_id is a BigInt).
|
|
const categoryRaw = sp.get("category");
|
|
let categoryId: bigint | undefined;
|
|
if (categoryRaw !== null) {
|
|
const parsed = positiveBigInt(categoryRaw);
|
|
if (!parsed) return apiError("A valid category id is required", 422);
|
|
categoryId = parsed;
|
|
}
|
|
|
|
try {
|
|
const where =
|
|
categoryId !== undefined
|
|
? eq(WebsiteRareValues.categoryId, categoryId)
|
|
: undefined;
|
|
|
|
const [totalRows, data] = await Promise.all([
|
|
db.select({ total: count() }).from(WebsiteRareValues).where(where),
|
|
db
|
|
.select({
|
|
id: WebsiteRareValues.id,
|
|
categoryId: WebsiteRareValues.categoryId,
|
|
itemId: WebsiteRareValues.itemId,
|
|
name: WebsiteRareValues.name,
|
|
creditValue: WebsiteRareValues.creditValue,
|
|
currencyValue: WebsiteRareValues.currencyValue,
|
|
currencyType: WebsiteRareValues.currencyType,
|
|
furnitureIcon: WebsiteRareValues.furnitureIcon,
|
|
})
|
|
.from(WebsiteRareValues)
|
|
.where(where)
|
|
.orderBy(asc(WebsiteRareValues.name))
|
|
.limit(take)
|
|
.offset(skip),
|
|
]);
|
|
const total = totalRows[0]?.total ?? 0;
|
|
|
|
return apiJson({
|
|
data,
|
|
meta: {
|
|
page,
|
|
perPage,
|
|
total,
|
|
lastPage: Math.max(1, Math.ceil(total / perPage)),
|
|
},
|
|
});
|
|
} catch {
|
|
// DB unreachable — never 500; return an empty, well-formed payload.
|
|
return apiJson(
|
|
{ data: [], meta: { page, perPage, total: 0, lastPage: 1 } },
|
|
{ status: 200 },
|
|
);
|
|
}
|
|
}
|