feat: list every wanted file with its upload

The wanted page lists every file the gaps report lacks, hashless ones included and marked, by system and most useful first, each with its own upload button to the folder validate_pr.placement() gives. Steps from a file in hand to its merge, copy without personal pronouns, list address versioned against stale caches.
This commit is contained in:
Abdessamad Derraz committed 2026-11-13 17:38:34 +01:00
1 parent aada55e656
commit 3fd61df038
9 files changed
+672 -84

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
// Read at build time by WantedFiles.astro and WantedList.astro: the first
// characters of the sha1 of public/data/wanted.json, added to its address.
// A browser that kept an older list in its cache asks for the new one: the
// two components read the list's current shape, and an older list broke
// them.
import { createHash } from 'node:crypto';
import { existsSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
// npm runs the build from website/, the project root.
const LIST = join(process.cwd(), 'public', 'data', 'wanted.json');
export const wantedVersion = (): string =>
existsSync(LIST) ? createHash('sha1').update(readFileSync(LIST)).digest('hex').slice(0, 12) : '';
+51 -4
View File
@@ -1,15 +1,20 @@
// The wanted page's reading of public/data/wanted.json (scripts/sitewanted.py):
// which entries a hashed file is, and where its upload goes.
// which entries a hashed file is, and where its upload goes. An entry
// with no h is known by its name only: a dropped file meets it by name,
// and the review of the upload decides.
import type { FileHashes } from './hashes.ts';
export type Entry = {
n: string;
h: { sha1?: string[]; sha256?: string[]; md5?: string[]; crc32?: string[] };
h?: { sha1?: string[]; sha256?: string[]; md5?: string[]; crc32?: string[] };
w: number[];
s?: string;
s?: number[];
r?: number;
z?: number[];
d?: string;
u?: string;
l?: [string, string][];
f?: number;
t?: string;
v?: number;
@@ -20,6 +25,7 @@ export type Wanted = {
issue: string;
limit: number;
readers: [string, string, string][];
systems: string[];
folders: string[];
entries: Entry[];
};
@@ -30,6 +36,7 @@ export type Wanted = {
// other wanted md5 starts with it. A crc32 is declared only where no
// stronger hash is, and a declared size bounds it.
export const satisfies = (entry: Entry, file: FileHashes, size: number): boolean => {
if (!entry.h) return false;
const { sha1, sha256, md5, crc32 } = entry.h;
if (sha1 && !sha1.includes(file.sha1)) return false;
if (sha256 && !sha256.includes(file.sha256)) return false;
@@ -41,11 +48,15 @@ export const satisfies = (entry: Entry, file: FileHashes, size: number): boolean
// The strongest hash an entry declares, the lowest first: a sha1 match
// settles the folder before an md5 or a crc32 one.
const strength = (entry: Entry) =>
entry.h.sha1 ? 0 : entry.h.sha256 ? 1 : entry.h.md5?.some((value) => value.length === 32) ? 2 : entry.h.md5 ? 3 : 4;
entry.h?.sha1 ? 0 : entry.h?.sha256 ? 1 : entry.h?.md5?.some((value) => value.length === 32) ? 2 : entry.h?.md5 ? 3 : 4;
export const matches = (data: Wanted, file: FileHashes, size: number): Entry[] =>
data.entries.filter((entry) => satisfies(entry, file, size)).sort((a, b) => strength(a) - strength(b));
// The entries known by their name only that a file of this name may be.
export const byName = (data: Wanted, name: string): Entry[] =>
data.entries.filter((entry) => !entry.h && entry.n.toLowerCase() === name.toLowerCase());
// The folder and the name an upload carries, as validate_pr.Placement
// gives them: the declared name, beside the held file of that name in
// .variants/ with the first 8 characters of the sha1, or the file's own
@@ -57,6 +68,31 @@ export const target = (data: Wanted, entry: Entry, file: FileHashes, ownName: st
return { folder, name: entry.t };
};
// Where the list sends a file before it is read: the drop target, under
// the name the declarations give. A variant's name ends with the first 8
// characters of its sha1: with no single sha1 declared, the name is known
// once the file is dropped, and name is empty.
export const rowTarget = (data: Wanted, entry: Entry) => {
const folder = entry.f === undefined ? 'bios/' : data.folders[entry.f];
if (!entry.t) return { folder, name: entry.n };
if (!entry.v) return { folder, name: entry.t };
const sha1 = entry.h?.sha1?.length === 1 ? entry.h.sha1[0] : '';
return { folder: `${folder}.variants/`, name: sha1 ? `${entry.t}.${sha1.slice(0, 8)}` : '' };
};
// Too large for GitHub's upload page: every size the declarations allow
// is over the limit.
export const tooLarge = (data: Wanted, entry: Entry) => !!entry.z?.length && entry.z.every((size) => size > data.limit);
let loaded: Promise<Wanted> | null = null;
// The list, fetched once for the drop box and the list below it. The
// version (wanted-version.ts) keeps a cached older list out.
export const loadWanted = (base: string, version = ''): Promise<Wanted> =>
(loaded ??= fetch(`${base}data/wanted.json${version ? `?v=${version}` : ''}`).then((response) => {
if (!response.ok) throw new Error(`wanted.json: ${response.status}`);
return response.json();
}));
export const uploadUrl = (data: Wanted, folder: string) =>
data.upload + folder.replace(/\/$/, '').split('/').map(encodeURIComponent).join('/');
@@ -70,3 +106,14 @@ export const issueUrl = (data: Wanted, name: string, file: FileHashes, size: num
md5: file.md5,
size: String(size),
})}`;
// The issue form for a listed file too large for the browser, with the
// hashes and the size its declarations write.
export const rowIssueUrl = (data: Wanted, entry: Entry) =>
`${data.issue}&${new URLSearchParams({
title: `[BIOS] Missing: ${entry.n}`,
filename: entry.n,
sha1: entry.h?.sha1?.[0] ?? '',
md5: entry.h?.md5?.find((value) => value.length === 32) ?? '',
size: entry.z?.length === 1 ? String(entry.z[0]) : '',
})}`;