feat: enrich tape identifier results with entry details

Show authors, genre, machine type, release year, CRC32, and a
prominent "View entry" link. Joins releases, genretypes, machinetypes,
and authors in lookupByMd5() for richer context.

opus-4-6@McFiver
This commit is contained in:
2026-02-17 16:38:34 +00:00
parent 5f84f482ab
commit fe1dfa4170
2 changed files with 99 additions and 17 deletions

View File

@@ -2633,6 +2633,11 @@ export type TapeMatch = {
md5: string;
crc32: string;
sizeBytes: number;
machinetype: string | null;
genre: string | null;
releaseYear: number | null;
authors: string[];
downloadLink: string;
};
export async function lookupByMd5(md5: string): Promise<TapeMatch[]> {
@@ -2645,12 +2650,46 @@ export async function lookupByMd5(md5: string): Promise<TapeMatch[]> {
md5: softwareHashes.md5,
crc32: softwareHashes.crc32,
sizeBytes: softwareHashes.sizeBytes,
machinetypeName: machinetypes.name,
genreName: genretypes.name,
releaseYear: releases.releaseYear,
downloadLink: downloads.fileLink,
})
.from(softwareHashes)
.innerJoin(downloads, eq(downloads.id, softwareHashes.downloadId))
.innerJoin(entries, eq(entries.id, downloads.entryId))
.leftJoin(machinetypes, eq(machinetypes.id, entries.machinetypeId))
.leftJoin(genretypes, eq(genretypes.id, entries.genretypeId))
.leftJoin(
releases,
and(eq(releases.entryId, downloads.entryId), eq(releases.releaseSeq, downloads.releaseSeq))
)
.where(eq(softwareHashes.md5, md5.toLowerCase()));
// Collect unique entry IDs to fetch authors
const entryIds = [...new Set(rows.map((r) => Number(r.entryId)))];
const authorMap = new Map<number, string[]>();
if (entryIds.length > 0) {
try {
const authorRows = await db
.select({ entryId: authors.entryId, name: labels.name })
.from(authors)
.innerJoin(labels, eq(labels.id, authors.labelId))
.where(
entryIds.length === 1
? eq(authors.entryId, entryIds[0])
: sql`${authors.entryId} in (${sql.join(entryIds.map((id) => sql`${id}`), sql`, `)})`
)
.orderBy(asc(authors.authorSeq));
for (const a of authorRows) {
const eid = Number(a.entryId);
const existing = authorMap.get(eid);
if (existing) existing.push(a.name);
else authorMap.set(eid, [a.name]);
}
} catch {}
}
return rows.map((r) => ({
downloadId: Number(r.downloadId),
entryId: Number(r.entryId),
@@ -2659,5 +2698,10 @@ export async function lookupByMd5(md5: string): Promise<TapeMatch[]> {
md5: r.md5,
crc32: r.crc32,
sizeBytes: Number(r.sizeBytes),
machinetype: r.machinetypeName ?? null,
genre: r.genreName ?? null,
releaseYear: r.releaseYear != null ? Number(r.releaseYear) : null,
authors: authorMap.get(Number(r.entryId)) ?? [],
downloadLink: r.downloadLink,
}));
}