Files
EpicNext-Cms/src/app/admin/items/page.tsx
T
openhands 7b249a7222
CI / check (push) Canceled after 0s
CI / tests-unit (push) Canceled after 0s
CI / tests-integration (push) Canceled after 0s
CI / tests-ui (push) Canceled after 0s
CI / preflight (push) Canceled after 0s
CI / deploy (push) Canceled after 0s
Gitea Runner Clean Test / test-job (push) Canceled after 0s
Gitea Actions Runner Test / test-job (push) Canceled after 0s
P1-P3 admin cleanup: rank guard, SSRF guard, count caching, dead code removal, pagination rewrite
- P1: new src/lib/admin/rank-guard.ts with tryGuardRank/guardRank + RankGuardTarget/Result; extracted from users.ts; applied to admin-bans (create/lift + rank redirect) and admin-badges (caps + rank guard + error surfacing); import-url-safety.ts SSRF guard wired into clone save+icon fetch; logAudit await in help-tickets; antiddos mutations SETTINGS_EDIT; markAllAlertsRead NOTIFICATIONS_EDIT; rankError/saveError in all 25 message files; tests rew/new for bans/badges/rank-guard/import-url-safety

- P2: ticket-inbox merged pagination reworked to single UNION ALL SQL with LIMIT/OFFSET (avoids O(offset) materialization); getCachedAdminCount with cacheFiltered option applied to devops/errors/photos/items/guilds/help-tickets/moderation pages; admin-theme catches→?error=1+banner+25 locales; logger in silent catches (rare-values/writeable-boxes); catalog-items-loader CAST→plain equality; count caching helper extended with opt-in cacheFiltered

- P3: removed dead modules is-staff/notice/recent-furni-resync/log-filters plus load-user-sanctions/user-sanction-timeline; removed orphaned CATALOG_PAGE_COLUMNS re-export; removed getFurniIconUrl from studio-furni-icons

Build: lint 0, typecheck 0, 3480 tests pass, i18n:check exit 0, colors exit 0. Circular chunk warning (9452/10535/66463) is webpack code-splitting artifact; build succeeds.
2026-10-12 17:42:19 +02:00

101 lines
2.8 KiB
TypeScript

import { and, desc, eq, like, or } from "drizzle-orm";
import { Package } from "lucide-react";
import { getTranslations } from "next-intl/server";
import { AdminPageShell } from "@/components/admin/admin-page-shell";
import { fetchAdminList } from "@/lib/admin-list";
import { db, ItemsBase } from "@/lib/db";
import { canAccess, PERMS } from "@/lib/permissions";
import { getCachedAdminCount } from "@/lib/services/admin-stats";
import { type ItemsBaseRow, ItemsTable } from "./items-table";
export default async function ItemsBasePage({
params: paramsPromise,
searchParams,
}: {
params: Promise<{ locale: string }>;
searchParams: Promise<Record<string, string>>;
}) {
const result = await fetchAdminList<ItemsBaseRow>(
{
permission: PERMS.CATALOG_VIEW,
fetch: async ({ search, page, perPage, rawParams }) => {
const conditions = [];
if (search) {
const ors = [
like(ItemsBase.itemName, `%${search}%`),
like(ItemsBase.publicName, `%${search}%`),
];
const asId = Number(search);
if (Number.isFinite(asId) && asId > 0) {
ors.push(eq(ItemsBase.id, asId));
}
conditions.push(or(...ors));
}
if (rawParams.filter_type) {
conditions.push(eq(ItemsBase.type, rawParams.filter_type));
}
const where = conditions.length > 0 ? and(...conditions) : undefined;
const [rows, total] = await Promise.all([
db
.select({
id: ItemsBase.id,
spriteId: ItemsBase.spriteId,
publicName: ItemsBase.publicName,
itemName: ItemsBase.itemName,
type: ItemsBase.type,
interactionType: ItemsBase.interactionType,
width: ItemsBase.width,
length: ItemsBase.length,
})
.from(ItemsBase)
.where(where)
.orderBy(desc(ItemsBase.id))
.limit(perPage)
.offset((page - 1) * perPage),
getCachedAdminCount(ItemsBase, "items_base", where),
]);
return {
rows: rows.map((r) => ({
id: r.id,
spriteId: r.spriteId,
publicName: r.publicName || "",
itemName: r.itemName || "",
type: r.type || "s",
interactionType: r.interactionType || "default",
width: r.width,
length: r.length,
})),
total,
};
},
},
paramsPromise,
searchParams,
);
const t = await getTranslations("pages.admin.items");
const canEdit = canAccess(
result.permissions,
PERMS.CATALOG_EDIT,
result.rank,
);
return (
<AdminPageShell icon={Package} title={t("title")} subtitle={t("subtitle")}>
<p className="text-muted-foreground m-0">
{t("total", { count: result.total })}
</p>
<ItemsTable
data={{
rows: result.rows,
total: result.total,
page: result.page,
perPage: result.perPage,
lastPage: result.lastPage,
}}
canEdit={canEdit}
/>
</AdminPageShell>
);
}