Fix build errors
This commit is contained in:
@@ -6,7 +6,7 @@ import type { Config } from "drizzle-kit";
|
||||
export default {
|
||||
schema: "./src/server/schema/**/*.ts",
|
||||
out: "./drizzle",
|
||||
driver: "mysql2",
|
||||
dialect: "mysql",
|
||||
dbCredentials: {
|
||||
// Read from env at runtime when using drizzle-kit
|
||||
url: process.env.ZXDB_URL!,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { notFound } from 'next/navigation';
|
||||
import Link from 'next/link';
|
||||
import { Register } from '@/utils/register_parser';
|
||||
import RegisterDetail from '@/app/registers/RegisterDetail';
|
||||
import {Container, Row} from "react-bootstrap";
|
||||
import { getRegisters } from '@/services/register.service';
|
||||
|
||||
@@ -62,7 +62,6 @@ export default function ZxdbExplorer({
|
||||
const json: Paged<Item> = await res.json();
|
||||
setData(json);
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(e);
|
||||
setData({ items: [], page: 1, pageSize, total: 0 });
|
||||
} finally {
|
||||
|
||||
@@ -91,7 +91,6 @@ export default function EntriesExplorer({
|
||||
const json: Paged<Item> = await res.json();
|
||||
setData(json);
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(e);
|
||||
setData({ items: [], page: 1, pageSize, total: 0 });
|
||||
} finally {
|
||||
@@ -105,7 +104,6 @@ export default function EntriesExplorer({
|
||||
setData(initial);
|
||||
setPage(initial.page);
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [initial]);
|
||||
|
||||
// Client fetch when filters/paging/sort change; also keep URL in sync
|
||||
|
||||
@@ -68,7 +68,7 @@ export type EntryDetailData = {
|
||||
}[];
|
||||
};
|
||||
|
||||
export default function EntryDetailClient({ data }: { data: EntryDetailData }) {
|
||||
export default function EntryDetailClient({ data }: { data: EntryDetailData | null }) {
|
||||
if (!data) return <div className="alert alert-warning">Not found</div>;
|
||||
|
||||
return (
|
||||
|
||||
@@ -17,10 +17,14 @@ export default function LabelDetailClient({ id, initial, initialTab, initialQ }:
|
||||
const router = useRouter();
|
||||
// Names are now delivered by SSR payload to minimize pop-in.
|
||||
|
||||
if (!initial || !initial.label) return <div className="alert alert-warning">Not found</div>;
|
||||
// Hooks must be called unconditionally
|
||||
const current = useMemo<Paged<Item> | null>(
|
||||
() => (tab === "authored" ? initial?.authored : initial?.published) ?? null,
|
||||
[initial, tab]
|
||||
);
|
||||
const totalPages = useMemo(() => (current ? Math.max(1, Math.ceil(current.total / current.pageSize)) : 1), [current]);
|
||||
|
||||
const current = useMemo(() => (tab === "authored" ? initial.authored : initial.published), [initial, tab]);
|
||||
const totalPages = useMemo(() => Math.max(1, Math.ceil(current.total / current.pageSize)), [current]);
|
||||
if (!initial || !initial.label) return <div className="alert alert-warning">Not found</div>;
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -98,19 +102,19 @@ export default function LabelDetailClient({ id, initial, initialTab, initialQ }:
|
||||
</div>
|
||||
|
||||
<div className="d-flex align-items-center gap-2 mt-2">
|
||||
<span>Page {current.page} / {totalPages}</span>
|
||||
<span>Page {current ? current.page : 1} / {totalPages}</span>
|
||||
<div className="ms-auto d-flex gap-2">
|
||||
<Link
|
||||
className={`btn btn-sm btn-outline-secondary ${current.page <= 1 ? "disabled" : ""}`}
|
||||
aria-disabled={current.page <= 1}
|
||||
href={`/zxdb/labels/${id}?${(() => { const p = new URLSearchParams(); p.set("tab", tab); if (q) p.set("q", q); p.set("page", String(Math.max(1, current.page - 1))); return p.toString(); })()}`}
|
||||
className={`btn btn-sm btn-outline-secondary ${current && current.page <= 1 ? "disabled" : ""}`}
|
||||
aria-disabled={current ? current.page <= 1 : true}
|
||||
href={`/zxdb/labels/${id}?${(() => { const p = new URLSearchParams(); p.set("tab", tab); if (q) p.set("q", q); p.set("page", String(Math.max(1, (current ? current.page : 1) - 1))); return p.toString(); })()}`}
|
||||
>
|
||||
Prev
|
||||
</Link>
|
||||
<Link
|
||||
className={`btn btn-sm btn-outline-secondary ${current.page >= totalPages ? "disabled" : ""}`}
|
||||
aria-disabled={current.page >= totalPages}
|
||||
href={`/zxdb/labels/${id}?${(() => { const p = new URLSearchParams(); p.set("tab", tab); if (q) p.set("q", q); p.set("page", String(Math.min(totalPages, current.page + 1))); return p.toString(); })()}`}
|
||||
className={`btn btn-sm btn-outline-secondary ${current && current.page >= totalPages ? "disabled" : ""}`}
|
||||
aria-disabled={current ? current.page >= totalPages : true}
|
||||
href={`/zxdb/labels/${id}?${(() => { const p = new URLSearchParams(); p.set("tab", tab); if (q) p.set("q", q); p.set("page", String(Math.min(totalPages, (current ? current.page : 1) + 1))); return p.toString(); })()}`}
|
||||
>
|
||||
Next
|
||||
</Link>
|
||||
|
||||
@@ -104,7 +104,6 @@ export default function ReleasesExplorer({
|
||||
const json: Paged<Item> = await res.json();
|
||||
setData(json);
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(e);
|
||||
setData({ items: [], page: 1, pageSize, total: 0 });
|
||||
} finally {
|
||||
@@ -117,7 +116,6 @@ export default function ReleasesExplorer({
|
||||
setData(initial);
|
||||
setPage(initial.page);
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [initial]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -141,7 +139,6 @@ export default function ReleasesExplorer({
|
||||
}
|
||||
updateUrl(page);
|
||||
fetchData(q, page);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [page, year, sort, dLanguageId, dMachinetypeId, filetypeId, schemetypeId, sourcetypeId, casetypeId, isDemo]);
|
||||
|
||||
function onSubmit(e: React.FormEvent) {
|
||||
@@ -286,7 +283,7 @@ export default function ReleasesExplorer({
|
||||
<label className="form-check-label" htmlFor="demoCheck">Demo only</label>
|
||||
</div>
|
||||
<div className="col-auto">
|
||||
<select className="form-select" value={sort} onChange={(e) => { setSort(e.target.value); setPage(1); }}>
|
||||
<select className="form-select" value={sort} onChange={(e) => { setSort(e.target.value as typeof sort); setPage(1); }}>
|
||||
<option value="year_desc">Sort: Newest</option>
|
||||
<option value="year_asc">Sort: Oldest</option>
|
||||
<option value="title">Sort: Title</option>
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import * as Icon from "react-bootstrap-icons";
|
||||
import { Navbar, Nav, Container, Dropdown } from "react-bootstrap";
|
||||
import { Navbar, Nav, Container } from "react-bootstrap";
|
||||
import ThemeDropdown from "@/components/ThemeDropdown";
|
||||
|
||||
export default function NavbarClient() {
|
||||
|
||||
@@ -26,7 +26,6 @@ function formatErrors(errors: z.ZodFormattedError<Map<string, string>, string>)
|
||||
const parsed = serverSchema.safeParse(process.env);
|
||||
if (!parsed.success) {
|
||||
// Fail fast with helpful output in server context
|
||||
// eslint-disable-next-line no-console
|
||||
console.error("❌ Invalid environment variables:\n" + formatErrors(parsed.error.format()));
|
||||
throw new Error("Invalid environment variables");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { and, desc, eq, like, sql, asc } from "drizzle-orm";
|
||||
import { alias } from "drizzle-orm/mysql-core";
|
||||
// import { alias } from "drizzle-orm/mysql-core";
|
||||
import { db } from "@/server/db";
|
||||
import {
|
||||
entries,
|
||||
@@ -88,7 +88,7 @@ export async function searchEntries(params: SearchParams): Promise<PagedResult<S
|
||||
|
||||
const [items, countRows] = await Promise.all([
|
||||
(async () => {
|
||||
let q1 = db
|
||||
const q1 = db
|
||||
.select({
|
||||
id: entries.id,
|
||||
title: entries.title,
|
||||
@@ -100,12 +100,12 @@ export async function searchEntries(params: SearchParams): Promise<PagedResult<S
|
||||
})
|
||||
.from(entries)
|
||||
.leftJoin(machinetypes, eq(machinetypes.id, entries.machinetypeId))
|
||||
.leftJoin(languages, eq(languages.id, entries.languageId));
|
||||
if (whereExpr) q1 = q1.where(whereExpr);
|
||||
return q1
|
||||
.leftJoin(languages, eq(languages.id, entries.languageId))
|
||||
.where(whereExpr ?? sql`true`)
|
||||
.orderBy(sort === "id_desc" ? desc(entries.id) : entries.title)
|
||||
.limit(pageSize)
|
||||
.offset(offset);
|
||||
return q1;
|
||||
})(),
|
||||
db
|
||||
.select({ total: sql<number>`count(*)` })
|
||||
@@ -373,9 +373,10 @@ export async function getEntryById(id: number): Promise<EntryDetail | null> {
|
||||
|
||||
const downloadsBySeq = new Map<number, DownloadRow[]>();
|
||||
for (const row of downloadRows) {
|
||||
const arr = downloadsBySeq.get(row.releaseSeq) ?? [];
|
||||
const key = Number(row.releaseSeq);
|
||||
const arr = downloadsBySeq.get(key) ?? [];
|
||||
arr.push(row);
|
||||
downloadsBySeq.set(row.releaseSeq, arr);
|
||||
downloadsBySeq.set(key, arr);
|
||||
}
|
||||
|
||||
// Build a map of downloads grouped by release_seq
|
||||
@@ -386,22 +387,22 @@ export async function getEntryById(id: number): Promise<EntryDetail | null> {
|
||||
type: { id: null, name: null },
|
||||
language: { id: null, name: null },
|
||||
machinetype: { id: null, name: null },
|
||||
year: (r.year) ?? null,
|
||||
year: r.year != null ? Number(r.year) : null,
|
||||
comments: null,
|
||||
downloads: (downloadsBySeq.get(Number(r.releaseSeq)) ?? []).map((d) => ({
|
||||
id: d.id,
|
||||
id: Number(d.id),
|
||||
link: d.link,
|
||||
size: d.size ?? null,
|
||||
size: d.size != null ? Number(d.size) : null,
|
||||
md5: d.md5 ?? null,
|
||||
comments: d.comments ?? null,
|
||||
isDemo: !!d.isDemo,
|
||||
type: { id: d.filetypeId, name: d.filetypeName },
|
||||
type: { id: Number(d.filetypeId), name: d.filetypeName },
|
||||
language: { id: (d.dlLangId) ?? null, name: (d.dlLangName) ?? null },
|
||||
machinetype: { id: (d.dlMachineId) ?? null, name: (d.dlMachineName) ?? null },
|
||||
machinetype: { id: d.dlMachineId != null ? Number(d.dlMachineId) : null, name: (d.dlMachineName) ?? null },
|
||||
scheme: { id: (d.schemeId) ?? null, name: (d.schemeName) ?? null },
|
||||
source: { id: (d.sourceId) ?? null, name: (d.sourceName) ?? null },
|
||||
case: { id: (d.caseId) ?? null, name: (d.caseName) ?? null },
|
||||
year: (d.year) ?? null,
|
||||
year: d.year != null ? Number(d.year) : null,
|
||||
})),
|
||||
}));
|
||||
|
||||
@@ -437,19 +438,19 @@ export async function getEntryById(id: number): Promise<EntryDetail | null> {
|
||||
: [],
|
||||
releases: releasesData,
|
||||
downloadsFlat: downloadFlatRows.map((d) => ({
|
||||
id: d.id,
|
||||
id: Number(d.id),
|
||||
link: d.link,
|
||||
size: d.size ?? null,
|
||||
size: d.size != null ? Number(d.size) : null,
|
||||
md5: d.md5 ?? null,
|
||||
comments: d.comments ?? null,
|
||||
isDemo: !!d.isDemo,
|
||||
type: { id: d.filetypeId, name: d.filetypeName },
|
||||
type: { id: Number(d.filetypeId), name: d.filetypeName },
|
||||
language: { id: (d.dlLangId) ?? null, name: (d.dlLangName) ?? null },
|
||||
machinetype: { id: (d.dlMachineId) ?? null, name: (d.dlMachineName) ?? null },
|
||||
machinetype: { id: d.dlMachineId != null ? Number(d.dlMachineId) : null, name: (d.dlMachineName) ?? null },
|
||||
scheme: { id: (d.schemeId) ?? null, name: (d.schemeName) ?? null },
|
||||
source: { id: (d.sourceId) ?? null, name: (d.sourceName) ?? null },
|
||||
case: { id: (d.caseId) ?? null, name: (d.caseName) ?? null },
|
||||
year: (d.year) ?? null,
|
||||
year: d.year != null ? Number(d.year) : null,
|
||||
releaseSeq: Number(d.releaseSeq),
|
||||
})),
|
||||
};
|
||||
@@ -457,7 +458,7 @@ export async function getEntryById(id: number): Promise<EntryDetail | null> {
|
||||
|
||||
// ----- Labels -----
|
||||
|
||||
export interface LabelDetail extends LabelSummary {}
|
||||
export type LabelDetail = LabelSummary;
|
||||
|
||||
export interface LabelSearchParams {
|
||||
q?: string;
|
||||
@@ -482,20 +483,18 @@ export async function searchLabels(params: LabelSearchParams): Promise<PagedResu
|
||||
return { items: items, page, pageSize, total };
|
||||
}
|
||||
|
||||
// Using helper search_by_names for efficiency
|
||||
// Using helper search_by_names for efficiency via subselect to avoid raw identifier typing
|
||||
const pattern = `%${q}%`;
|
||||
const countRows = await db
|
||||
.select({ total: sql<number>`count(distinct ${sql.identifier("label_id")})` })
|
||||
.from(sql`search_by_names`)
|
||||
.where(like(sql.identifier("label_name"), pattern));
|
||||
.select({ total: sql<number>`count(*)` })
|
||||
.from(labels)
|
||||
.where(sql`${labels.id} in (select distinct label_id from search_by_names where label_name like ${pattern})`);
|
||||
const total = Number(countRows[0]?.total ?? 0);
|
||||
|
||||
const items = await db
|
||||
.select({ id: labels.id, name: labels.name, labeltypeId: labels.labeltypeId })
|
||||
.from(sql`search_by_names`)
|
||||
.innerJoin(labels, eq(labels.id, sql.identifier("label_id")))
|
||||
.where(like(sql.identifier("label_name"), pattern))
|
||||
.groupBy(labels.id)
|
||||
.from(labels)
|
||||
.where(sql`${labels.id} in (select distinct label_id from search_by_names where label_name like ${pattern})`)
|
||||
.orderBy(labels.name)
|
||||
.limit(pageSize)
|
||||
.offset(offset);
|
||||
|
||||
Reference in New Issue
Block a user