Archive: both teams or no game, legends are events, every match redone; faces keep to the sport
A folder is matched to an official game only when both teams are recognised (never a first team for its B side); legends', veterans', charity and exhibition games never get a championship fixture; every match but a manual one is made again on start and every six hours (one failing folder never stops the rest), renaming events to clean team names. The viewer merges teams written with dates before them and known teams under one name. Faces are never suggested as someone of another sport, and old such suggestions are taken away. Visible loading in the archive site. More archive work at once (previews, images in flight, face processes). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HT6iXLYUUp9pJz5Kza9xCW
This commit is contained in:
1 parent
ea63b30452
commit
303aedef80
11 files changed
+417
-57
No files matched your search
@@ -363,9 +363,17 @@ export function isInitials(short: string, name: string): boolean {
|
||||
}
|
||||
|
||||
/** A folder's team name against a team: its name ("Sporting CP"), abbreviation ("SCP"), initials or slug. */
|
||||
/** A reserve, youth or women's side named ("Benfica B", "Sporting Sub-23", "ABC Feminino"). */
|
||||
export const isVariantSide = (s: string) =>
|
||||
/\b(b|sub[\s-]?\d{2}|u[\s-]?\d{2}|feminin[oa]s?|fem\.?|juniores|juvenis|iniciados|infantis|benjamins|revela[cç][aã]o)\b/i.test(
|
||||
s.normalize("NFD").replace(/[\u0300-\u036f]/g, ""),
|
||||
);
|
||||
|
||||
export function isTeam(name: string, team: { name: string; abbreviation: string | null; slug: string }): boolean {
|
||||
const n = fold(name);
|
||||
if (!n) return false;
|
||||
// "SL Benfica" is never "SL Benfica B", nor the other way round.
|
||||
if (isVariantSide(name) !== isVariantSide(team.name) && fold(team.abbreviation ?? "") !== n) return false;
|
||||
if (team.abbreviation && fold(team.abbreviation) === n) return true;
|
||||
if (fold(team.slug) === n || fold(team.name) === n) return true;
|
||||
if (sameTeam(name, team.name)) return true;
|
||||
@@ -385,6 +393,41 @@ export const lisbonDay = (d: Date) => new Intl.DateTimeFormat("en-CA", { timeZon
|
||||
* The official game of a folder among candidate fixtures: same teams (home and away, or swapped as a last resort),
|
||||
* then the same day, or the same competition, season and matchday. Null when not exactly one fits.
|
||||
*/
|
||||
/**
|
||||
* Games outside any official competition: legends' and veterans' tournaments, charity, exhibition and tribute games,
|
||||
* galas. They are events with games in them, never matched to a championship's fixture.
|
||||
*/
|
||||
const EXHIBITION = /\b(legends?|lendas|veteranos|old ?boys|solidari[oa]|beneficen[ct]i?a|exibi[cç][aã]o|homenagem|despedida|gala|festa|showcase|all[ -]?stars?)\b/i;
|
||||
const isExhibitionName = (x: string) => EXHIBITION.test(x.normalize("NFD").replace(/[\u0300-\u036f]/g, ""));
|
||||
export function isExhibition(game: Pick<FolderGame, "home" | "away" | "parents">): boolean {
|
||||
return [game.home, game.away, ...game.parents].some((x) => !!x && isExhibitionName(x));
|
||||
}
|
||||
/** The tournament or occasion an exhibition game belongs to ("Liga Portugal Legends 2025-26"), from the folders above. */
|
||||
export function exhibitionName(game: Pick<FolderGame, "parents">): string | null {
|
||||
return game.parents.find(isExhibitionName)?.trim() ?? null;
|
||||
}
|
||||
|
||||
/** A team's name as written in a folder without the date or number before it ("01.23 Leixões SC", "02_Estoril Praia"). */
|
||||
export function teamLabel(name: string): string {
|
||||
return name
|
||||
.replace(/\(c[oó]pia(r)?\)/gi, " ")
|
||||
.replace(/\s+/g, " ")
|
||||
// The numbers, dates and separators before the name ("10 .22 ", "02_", "01.2023 "), never a name's own "1º".
|
||||
.replace(/^[\d\s._-]*\d[\d._-]*[\s._-]+(?=\S)/, "")
|
||||
.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* The known team a folder's name means, when exactly one fits (abbreviation, initials, name or close name): its
|
||||
* official name, so "SCP", "Sporting" and "Sporting CP" are one team. The cleaned name otherwise.
|
||||
*/
|
||||
export function canonicalTeam(name: string, teams: readonly { name: string; abbreviation: string | null; slug: string }[]): string {
|
||||
const label = teamLabel(name);
|
||||
if (!label) return name.trim();
|
||||
const fits = [...new Map(teams.filter((t) => isTeam(label, t)).map((t) => [fold(t.name), t])).values()];
|
||||
return fits.length === 1 ? fits[0]!.name : label;
|
||||
}
|
||||
|
||||
export function pickFixture(game: FolderGame, fixtures: FixtureCandidate[], now = new Date()): FixtureCandidate | null {
|
||||
// A game still to be played has no photos yet.
|
||||
fixtures = fixtures.filter((f) => f.startsAt.getTime() <= now.getTime() + 6 * 3600_000);
|
||||
@@ -402,6 +445,7 @@ export function pickFixture(game: FolderGame, fixtures: FixtureCandidate[], now
|
||||
// Only a dated folder, or one placed in its competition, season and matchday ("LPBetclic 26-27/Jornada 5"), is an
|
||||
// official game: a season, a month or a matchday alone says too little (the same pairing is played again, by the
|
||||
// B team, the youth, the women), and a wrong game is worse than none.
|
||||
if (isExhibition(game)) return null;
|
||||
const placed = !!(game.competition && game.season && game.round);
|
||||
if (!game.day && !placed && !(game.single && game.month)) return null;
|
||||
// A reserve, youth or women's side ("Sporting B", "Sub-23", "Feminino") is never the first team's game.
|
||||
@@ -429,17 +473,6 @@ export function pickFixture(game: FolderGame, fixtures: FixtureCandidate[], now
|
||||
const same = found.filter((f) => lisbonDay(f.startsAt) === game.day);
|
||||
if (same.length === 1) return same[0]!;
|
||||
}
|
||||
// One side not recognised (a nickname, a sponsor's name): the only game that day of that competition with the other.
|
||||
if (!found.length && game.day && game.competition) {
|
||||
const onDay = pool.filter((f) => lisbonDay(f.startsAt) === game.day);
|
||||
const half = onDay.filter((f) => isTeam(game.home, f.homeTeam) || isTeam(game.away, f.awayTeam));
|
||||
const only = half[0];
|
||||
if (half.length === 1 && only) {
|
||||
// ... unless the other name is a team of another game that day: then the folder is not this game.
|
||||
const other = isTeam(game.home, only.homeTeam) ? game.away : game.home;
|
||||
const elsewhere = onDay.some((f) => f !== only && (isTeam(other, f.homeTeam) || isTeam(other, f.awayTeam)));
|
||||
if (!elsewhere) return only;
|
||||
}
|
||||
}
|
||||
// Both teams must be recognised: a game with one side guessed is not matched (a wrong game is worse than none).
|
||||
return null;
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import { ingestWindow } from "../library/events.js";
|
||||
import { waitUntil } from "../lib/idle.js";
|
||||
import { CloudClient, cleanBase, pollLogin, startLogin, type CloudEntry } from "./nextcloud.js";
|
||||
import { describeFolder, type FolderGame, isInitials, isTeamName, lisbonDay, parseFolder, pastOrToday, pickFixture } from "./match.js";
|
||||
import { canonicalTeam, exhibitionName, isExhibition } from "./match.js";
|
||||
|
||||
export const IMAGE = /\.(jpe?g)$/i;
|
||||
/** How long the person has to authorise in their cloud (Nextcloud keeps the flow 20 minutes). */
|
||||
@@ -245,6 +246,11 @@ export class ArchiveService {
|
||||
|
||||
/** Sources whose time to be walked again has come (the worker runs this). */
|
||||
async scanDue(now = new Date()): Promise<number> {
|
||||
// Every gallery is checked again every six hours (on start too): new calendars, stricter rules.
|
||||
if (now.getTime() - this.verifiedAt > 6 * 3600_000) {
|
||||
this.verifiedAt = now.getTime();
|
||||
void this.verifyAll().catch((err) => this.deps.log.warn({ err }, "archive: galleries not checked"));
|
||||
}
|
||||
const due = await this.deps.db.cloudSource.findMany({ where: { status: { in: ["READY", "ERROR"] }, secretEnc: { not: null }, nextScanAt: { lte: now } }, select: { id: true } });
|
||||
for (const s of due) await this.scan(s.id);
|
||||
return due.length;
|
||||
@@ -360,7 +366,7 @@ export class ArchiveService {
|
||||
if (fixture) return { eventId: await this.eventForFixture(source, fixture), matchedBy: "FIXTURE" };
|
||||
const teams = await this.teamNames(game, source);
|
||||
const day = game.day ?? (game.month ? `${game.month}-15` : null);
|
||||
return { eventId: await this.eventForName(source, { ...teams, competition: game.competition, round: game.round }, day, modified, folder.eventId), matchedBy: "NAME" };
|
||||
return { eventId: await this.eventForName(source, { ...teams, competition: game.competition, competitionName: exhibitionName(game), round: game.round }, day, modified, folder.eventId), matchedBy: "NAME" };
|
||||
}
|
||||
return { eventId: await this.eventForOccasion(source, folder, modified), matchedBy: "FOLDER" };
|
||||
}
|
||||
@@ -405,11 +411,28 @@ export class ArchiveService {
|
||||
|
||||
/** Every cloud's galleries checked again (on start): games of another day, or still to come, put right. */
|
||||
async verifyAll(): Promise<number> {
|
||||
const sources = await this.deps.db.cloudSource.findMany({ where: { secretEnc: { not: null } }, select: { id: true } });
|
||||
let moved = 0;
|
||||
for (const s of sources) moved += await this.rematch(s.id);
|
||||
return moved;
|
||||
// One check at a time (on start, every six hours, after a season's calendar is read): a second call waits for it.
|
||||
this.verifying ??= (async () => {
|
||||
try {
|
||||
// Every cloud, signed in or not: the check needs only what was indexed.
|
||||
const sources = await this.deps.db.cloudSource.findMany({ select: { id: true } });
|
||||
let moved = 0;
|
||||
for (const s of sources) {
|
||||
try {
|
||||
moved += await this.rematch(s.id);
|
||||
} catch (err) {
|
||||
this.deps.log.warn({ err, sourceId: s.id }, "archive: cloud not checked");
|
||||
}
|
||||
}
|
||||
return moved;
|
||||
} finally {
|
||||
this.verifying = null;
|
||||
}
|
||||
})();
|
||||
return this.verifying;
|
||||
}
|
||||
private verifying: Promise<number> | null = null;
|
||||
private verifiedAt = Date.now();
|
||||
|
||||
async rematch(sourceId: string): Promise<number> {
|
||||
const { db, log } = this.deps;
|
||||
@@ -417,22 +440,30 @@ export class ArchiveService {
|
||||
const folders = await db.cloudFolder.findMany({ where: { sourceId, photoCount: { gt: 0 } } });
|
||||
let moved = 0;
|
||||
for (const folder of folders) {
|
||||
// An official game that is not the photos' (a day still to come, another day than they were taken): never
|
||||
// that game again; the folder gets the event of its own day.
|
||||
if (folder.matchedBy === "FIXTURE" && !folder.fixtureRejected && (await this.misdated(folder))) {
|
||||
await this.rejectFixture(folder.id);
|
||||
log.warn({ folderId: folder.id, path: folder.path }, "archive: gallery taken off a game of another day");
|
||||
moved++;
|
||||
continue;
|
||||
}
|
||||
if (folder.matchedBy === "NAME" || folder.matchedBy === "FOLDER" || !folder.eventId) {
|
||||
const target = await this.eventOf(source, folder, null);
|
||||
if (target.eventId !== folder.eventId || target.matchedBy !== folder.matchedBy) {
|
||||
await this.setFolderEvent(folder.id, { eventId: target.eventId }, target.matchedBy);
|
||||
// One folder that cannot be read again never stops the others from being checked.
|
||||
try {
|
||||
// An official game that is not the photos' (a day still to come, another day than they were taken): never
|
||||
// that game again; the folder gets the event of its own day.
|
||||
if (folder.matchedBy === "FIXTURE" && !folder.fixtureRejected && (await this.misdated(folder))) {
|
||||
await this.rejectFixture(folder.id);
|
||||
log.warn({ folderId: folder.id, path: folder.path }, "archive: gallery taken off a game of another day");
|
||||
moved++;
|
||||
continue;
|
||||
}
|
||||
// Every match but one made by hand is made again with today's rules (stricter ones put old mistakes right:
|
||||
// another game, or no official game at all).
|
||||
if (folder.matchedBy !== "MANUAL") {
|
||||
const target = await this.eventOf(source, folder, null);
|
||||
if (target.eventId !== folder.eventId || target.matchedBy !== folder.matchedBy) {
|
||||
if (folder.matchedBy === "FIXTURE") log.warn({ folderId: folder.id, path: folder.path, to: target.matchedBy }, "archive: gallery taken off a game that is not its own");
|
||||
await this.setFolderEvent(folder.id, { eventId: target.eventId }, target.matchedBy);
|
||||
moved++;
|
||||
}
|
||||
}
|
||||
await this.namePeople(folder);
|
||||
} catch (err) {
|
||||
log.warn({ err, folderId: folder.id, path: folder.path }, "archive: gallery not checked");
|
||||
}
|
||||
await this.namePeople(folder);
|
||||
}
|
||||
if (moved) log.info({ sourceId, moved }, "archive: galleries matched to their games");
|
||||
return moved;
|
||||
@@ -466,7 +497,8 @@ export class ArchiveService {
|
||||
}
|
||||
const list = this.teams.list;
|
||||
const resolve = (name: string): { name: string; short: string | null } => {
|
||||
if (!name || name.length > 6 || /\s/.test(name)) return { name, short: null };
|
||||
// A full name: the known team's official name when exactly one fits ("Sporting" → "Sporting CP").
|
||||
if (!name || name.length > 6 || /\s/.test(name)) return { name: name ? canonicalTeam(name, list) : name, short: null };
|
||||
const byAbbr = [...new Map(list.filter((t) => t.abbreviation && t.abbreviation.toUpperCase() === name.toUpperCase()).map((t) => [t.name, t])).values()];
|
||||
if (byAbbr.length === 1) return { name: byAbbr[0]!.name, short: name.toUpperCase() };
|
||||
const byInitials = [...new Map(list.filter((t) => isInitials(name, t.name)).map((t) => [t.name, t])).values()];
|
||||
@@ -523,6 +555,8 @@ export class ArchiveService {
|
||||
|
||||
private async findFixture(game: NonNullable<ReturnType<typeof parseFolder>>, source?: Pick<CloudSource, "baseUrl">) {
|
||||
if (!game.day && !game.month && !game.competition && !game.season) return null;
|
||||
// A legends' tournament, a charity game, a gala: games, but in no championship.
|
||||
if (isExhibition(game)) return null;
|
||||
const day = game.day ? new Date(`${game.day}T12:00:00Z`) : null;
|
||||
// A Liga season not read yet (an older one): its calendar comes from Liga Portugal first.
|
||||
// The Liga's own cloud, or a Liga competition folder.
|
||||
@@ -594,7 +628,7 @@ export class ArchiveService {
|
||||
|
||||
private async eventForName(
|
||||
source: CloudSource,
|
||||
g: { home: string; away: string; homeShort?: string | null; awayShort?: string | null; competition: string | null; round: string | null },
|
||||
g: { home: string; away: string; homeShort?: string | null; awayShort?: string | null; competition: string | null; competitionName?: string | null; round: string | null },
|
||||
day: string | null,
|
||||
modified: Date | null,
|
||||
current: string | null = null,
|
||||
@@ -603,8 +637,13 @@ export class ArchiveService {
|
||||
const { db } = this.deps;
|
||||
// The folder's own event still fits (read again, nothing new): kept.
|
||||
if (current && !occasion) {
|
||||
const e = await db.event.findUnique({ where: { id: current }, select: { home: true, away: true, homeShort: true, awayShort: true, startsAt: true, fixtureId: true, archivedAt: true } });
|
||||
if (e && !e.fixtureId && e.archivedAt && (!day || lisbonDay(e.startsAt) === day) && isTeamName(g.home, e.home, e.homeShort) && (g.away ? isTeamName(g.away, e.away, e.awayShort) : !e.away)) return current;
|
||||
const e = await db.event.findUnique({ where: { id: current }, select: { home: true, away: true, homeShort: true, awayShort: true, startsAt: true, fixtureId: true, archivedAt: true, competition: true } });
|
||||
if (e && !e.fixtureId && e.archivedAt && (!day || lisbonDay(e.startsAt) === day) && isTeamName(g.home, e.home, e.homeShort) && (g.away ? isTeamName(g.away, e.away, e.awayShort) : !e.away)) {
|
||||
// The same teams, now named better ("01.23 Leixões SC" → "Leixões SC"): the event takes the names.
|
||||
if (e.home !== g.home || e.away !== g.away || (g.competitionName && e.competition !== g.competitionName))
|
||||
await db.event.update({ where: { id: current }, data: { home: g.home, away: g.away, homeShort: g.homeShort ?? e.homeShort, awayShort: g.awayShort ?? e.awayShort, ...(g.competitionName && { competition: g.competitionName }) } });
|
||||
return current;
|
||||
}
|
||||
}
|
||||
if (day && !pastOrToday(day)) day = null;
|
||||
const startsAt = day ? new Date(`${day}T12:00:00Z`) : (modified ?? new Date());
|
||||
@@ -627,6 +666,7 @@ export class ArchiveService {
|
||||
homeShort: g.homeShort ?? null,
|
||||
awayShort: g.awayShort ?? null,
|
||||
competitionCode: g.competition && /^PO\d/i.test(g.competition) ? g.competition : null,
|
||||
competition: g.competitionName ?? null,
|
||||
round: g.round,
|
||||
startsAt,
|
||||
...ingestWindow(startsAt),
|
||||
|
||||
@@ -8,7 +8,7 @@ import type { SecretBox } from "../delivery/secrets.js";
|
||||
import { AppError, badRequest, notFound, unauthorized } from "../lib/errors.js";
|
||||
import type { UrlSigner } from "../storage/storage.js";
|
||||
import { CloudClient, pollLogin, startLogin } from "./nextcloud.js";
|
||||
import { describeFolder } from "./match.js";
|
||||
import { canonicalTeam, describeFolder } from "./match.js";
|
||||
import { facesOfPhotos, registerArchivePeopleRoutes } from "./people.js";
|
||||
import type { ArchiveService } from "./service.js";
|
||||
|
||||
@@ -169,6 +169,33 @@ export async function registerArchiveViewerRoutes(
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* The teams of the viewer's games under one name each: without the date or number a folder put before it ("01.23
|
||||
* Leixões SC"), and the known team's official name when exactly one fits ("SCP", "Sporting" → "Sporting CP").
|
||||
* Each with the names its galleries use, so filtering by it finds them all.
|
||||
*/
|
||||
const teamGroups = async (sourceId: string, games: Iterable<{ home: string; away: string }>): Promise<Map<string, { names: Set<string>; galleries: number }>> => {
|
||||
const source = await db.cloudSource.findUnique({ where: { id: sourceId }, select: { look: true, baseUrl: true } });
|
||||
const liga = source?.look === "liga" || /liga/i.test(source?.baseUrl ?? "");
|
||||
const known = await db.sportsTeam.findMany({ where: liga ? { provider: "LIGA" } : { provider: { not: "LIGA" }, sport: { not: "futebol" } }, select: { name: true, abbreviation: true, slug: true } });
|
||||
const out = new Map<string, { names: Set<string>; galleries: number }>();
|
||||
const byKey = new Map<string, string>();
|
||||
const fold = (x: string) => x.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
|
||||
for (const g of games)
|
||||
for (const raw of [g.home, g.away]) {
|
||||
if (!raw) continue;
|
||||
const name = canonicalTeam(raw, known);
|
||||
const key = fold(name);
|
||||
const label = byKey.get(key) ?? name;
|
||||
byKey.set(key, label);
|
||||
const cur = out.get(label) ?? { names: new Set<string>(), galleries: 0 };
|
||||
cur.names.add(raw);
|
||||
cur.galleries++;
|
||||
out.set(label, cur);
|
||||
}
|
||||
return out;
|
||||
};
|
||||
|
||||
/** Galleries the viewer may see, newest first; by words in the name, a team or a player. */
|
||||
app.get("/v1/archive/:sourceId/galleries", async (req) => {
|
||||
const { sourceId } = SourceParams.parse(req.params);
|
||||
@@ -176,9 +203,16 @@ export async function registerArchiveViewerRoutes(
|
||||
const query = ListQuery.parse(req.query);
|
||||
const visible = await visibleFolders(v);
|
||||
const words = (query.q ?? "").split(/\s+/).filter(Boolean);
|
||||
// A team of the directory: every name its galleries use.
|
||||
let teamNames: string[] = [];
|
||||
if (query.team) {
|
||||
const rows = await db.cloudFolder.findMany({ where: { ...folderWhere(v, visible), matchedBy: { not: "FOLDER" } }, select: { event: { select: { home: true, away: true } } } });
|
||||
const groups = await teamGroups(sourceId, rows.flatMap((r) => (r.event ? [r.event] : [])));
|
||||
teamNames = [...(groups.get(query.team)?.names ?? new Set([query.team]))];
|
||||
}
|
||||
const eventFilters = [
|
||||
...words.map((w) => ({ OR: [{ home: { contains: w, mode: "insensitive" as const } }, { away: { contains: w, mode: "insensitive" as const } }, { competition: { contains: w, mode: "insensitive" as const } }, { homeShort: { equals: w, mode: "insensitive" as const } }, { awayShort: { equals: w, mode: "insensitive" as const } }] })),
|
||||
...(query.team ? [{ OR: [{ home: { equals: query.team, mode: "insensitive" as const } }, { away: { equals: query.team, mode: "insensitive" as const } }] }] : []),
|
||||
...(query.team ? [{ OR: [{ home: { in: teamNames } }, { away: { in: teamNames } }] }] : []),
|
||||
...(query.player ? [{ photos: { some: { players: { has: query.player } } } }] : []),
|
||||
];
|
||||
const where = { ...folderWhere(v, visible), ...(eventFilters.length && { event: { AND: eventFilters } }) };
|
||||
@@ -215,10 +249,9 @@ export async function registerArchiveViewerRoutes(
|
||||
const visible = await visibleFolders(v);
|
||||
const folders = await db.cloudFolder.findMany({ where: folderWhere(v, visible), select: { eventId: true, matchedBy: true, event: { select: { id: true, home: true, away: true } } } });
|
||||
// Teams of games only (a session or a day of an event is named in "home" too), each game counted once.
|
||||
const teams = new Map<string, number>();
|
||||
const games = new Map<string, { home: string; away: string }>();
|
||||
for (const f of folders) if (f.event && f.matchedBy !== "FOLDER") games.set(f.event.id, f.event);
|
||||
for (const g of games.values()) for (const t of [g.home, g.away]) if (t) teams.set(t, (teams.get(t) ?? 0) + 1);
|
||||
const teams = new Map([...(await teamGroups(sourceId, games.values()))].map(([name, g]) => [name, g.galleries]));
|
||||
const eventIds = [...new Set(folders.map((f) => f.eventId!))];
|
||||
const players = eventIds.length
|
||||
? await db.$queryRaw<{ name: string; photos: bigint; club: string | null }[]>`
|
||||
|
||||
@@ -65,6 +65,11 @@ export class FaceService {
|
||||
}
|
||||
|
||||
async requeueStale(now = new Date()): Promise<number> {
|
||||
// On start, too: suggestions of someone of another sport (made before suggestions knew sports) taken away.
|
||||
await this.dropCrossSport().then(
|
||||
(n) => void (n && this.deps.log.warn({ groups: n }, "faces: suggestions of another sport taken away")),
|
||||
(err) => this.deps.log.warn({ err }, "faces: cross-sport suggestions not checked"),
|
||||
);
|
||||
const r = await this.deps.db.photo.updateMany({
|
||||
where: { facesStatus: "RUNNING", updatedAt: { lt: new Date(now.getTime() - STALE_RUNNING_MS) } },
|
||||
data: { facesStatus: "PENDING" },
|
||||
@@ -219,12 +224,21 @@ export class FaceService {
|
||||
}
|
||||
}
|
||||
|
||||
/** See `dropCrossSportSuggestions`. */
|
||||
dropCrossSport(): Promise<number> {
|
||||
return dropCrossSportSuggestions(this.deps.db);
|
||||
}
|
||||
|
||||
async refreshSuggestions(eventId: string): Promise<void> {
|
||||
const { db } = this.deps;
|
||||
await this.joinSamePerson(eventId);
|
||||
const groups = await db.faceGroup.findMany({ where: { eventId, personId: null, ignoredAt: null } });
|
||||
if (!groups.length) return;
|
||||
const people = await db.person.findMany({ where: { organizationId: groups[0]!.organizationId, NOT: { centroid: { isEmpty: true } } } });
|
||||
const everyone = await db.person.findMany({ where: { organizationId: groups[0]!.organizationId, NOT: { centroid: { isEmpty: true } } } });
|
||||
// Never someone of another sport (a footballer at a handball game): known by their squad's team.
|
||||
const sport = await eventSport(db, eventId);
|
||||
const sports = sport ? await peopleSports(db, everyone) : new Map<string, string>();
|
||||
const people = everyone.filter((p) => !sport || !sports.has(p.id) || sports.get(p.id) === sport);
|
||||
// Numbers as worn in this event's season and competition (another season, a cup, the national team: another).
|
||||
const ctx = await numberContext(db, eventId);
|
||||
const worn = new Map<string, string | null>();
|
||||
@@ -529,6 +543,59 @@ export class FaceService {
|
||||
}
|
||||
|
||||
/** Keeps `processes` face engines busy. */
|
||||
/** "Futebol", "football" → "futebol"; "Andebol", "handball" → "andebol". */
|
||||
export function normSport(s: string | null | undefined): string | null {
|
||||
const v = (s ?? "").normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().trim();
|
||||
if (!v) return null;
|
||||
if (/futebol|football|soccer/.test(v)) return "futebol";
|
||||
if (/andebol|handball/.test(v)) return "andebol";
|
||||
return v;
|
||||
}
|
||||
|
||||
/** The sport of an event: its own, its official game's, or its archive cloud's (Liga: football, FPA: handball). */
|
||||
export async function eventSport(db: Db, eventId: string): Promise<string | null> {
|
||||
const rows = await db.$queryRaw<{ sport: string | null }[]>`
|
||||
SELECT COALESCE(e.sport, c.sport, CASE s.look WHEN 'liga' THEN 'futebol' WHEN 'fpa' THEN 'andebol' END) AS sport
|
||||
FROM events e
|
||||
LEFT JOIN sports_fixtures f ON f.id = e.fixture_id
|
||||
LEFT JOIN sports_competitions c ON c.id = f.competition_id
|
||||
LEFT JOIN LATERAL (SELECT cs.look FROM cloud_folders cf JOIN cloud_sources cs ON cs.id = cf.source_id WHERE cf.event_id = e.id LIMIT 1) s ON true
|
||||
WHERE e.id = ${eventId}::uuid`;
|
||||
return normSport(rows[0]?.sport);
|
||||
}
|
||||
|
||||
/** Each person's sport, from the team of the squad they came from (people typed by hand have none). */
|
||||
export async function peopleSports(db: Db, people: { id: string; sportsPlayerId: string | null }[]): Promise<Map<string, string>> {
|
||||
const ids = [...new Set(people.map((p) => p.sportsPlayerId).filter((x): x is string => !!x))];
|
||||
if (!ids.length) return new Map();
|
||||
const players = await db.sportsPlayer.findMany({ where: { id: { in: ids } }, select: { id: true, team: { select: { sport: true } } } });
|
||||
const bySquad = new Map(players.map((p) => [p.id, normSport(p.team.sport)]));
|
||||
const out = new Map<string, string>();
|
||||
for (const p of people) {
|
||||
const sport = p.sportsPlayerId ? bySquad.get(p.sportsPlayerId) : null;
|
||||
if (sport) out.set(p.id, sport);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Suggestions of someone of another sport than the event's (made before suggestions knew sports) taken away;
|
||||
* names confirmed by a person stay. Returns how many.
|
||||
*/
|
||||
export async function dropCrossSportSuggestions(db: Db): Promise<number> {
|
||||
const n = await db.$executeRaw`
|
||||
UPDATE face_groups g SET suggested_person_id = NULL, suggestion_score = NULL
|
||||
FROM people p, sports_players sp, sports_teams t, events e
|
||||
LEFT JOIN sports_fixtures f ON f.id = e.fixture_id
|
||||
LEFT JOIN sports_competitions c ON c.id = f.competition_id
|
||||
WHERE g.suggested_person_id = p.id AND sp.id = p.sports_player_id AND t.id = sp.team_id AND e.id = g.event_id
|
||||
AND g.person_id IS NULL
|
||||
AND lower(t.sport) <> lower(COALESCE(e.sport, c.sport, (
|
||||
SELECT CASE cs.look WHEN 'liga' THEN 'futebol' WHEN 'fpa' THEN 'andebol' END
|
||||
FROM cloud_folders cf JOIN cloud_sources cs ON cs.id = cf.source_id WHERE cf.event_id = e.id LIMIT 1), lower(t.sport)))`;
|
||||
return n;
|
||||
}
|
||||
|
||||
export class FaceWorker {
|
||||
private inFlight = 0;
|
||||
private timer: NodeJS.Timeout | undefined;
|
||||
|
||||
@@ -44,12 +44,14 @@ export function planCapacity(
|
||||
cpus,
|
||||
memoryGb: Math.round(memoryGb * 10) / 10,
|
||||
// Face processes wait idle when there is nothing to analyse (memory only): enough for an archive's backlog.
|
||||
faces: set.faces ?? clamp(Math.min(cpus * 0.45, byMemory("faces", 0.4)), 2, 32),
|
||||
faces: set.faces ?? clamp(Math.min(cpus * 0.9, byMemory("faces", 0.5)), 2, 64),
|
||||
ingest: set.ingest ?? clamp(Math.min(cpus * 0.25, byMemory("ingest", 0.15)), 4, 32),
|
||||
archive: set.archive ?? clamp(Math.min(cpus * 0.3, byMemory("archive", 0.2)), 2, 32),
|
||||
// A fixed ARCHIVE_CONCURRENCY sets the everyday pace; a big backlog still gets the machine's share.
|
||||
archiveBurst: Math.max(set.archive ?? 0, clamp(Math.min(cpus * 0.75, byMemory("archive", 0.35)), 2, 64)),
|
||||
archiveDownloads: clamp(Math.max(16, cpus * 4), 16, 192),
|
||||
// A backlog to clear gets as much as the machine has: previews several per core (each waits on disk and the
|
||||
// database too), and many more images in flight, which mostly wait for the cloud.
|
||||
archiveBurst: Math.max(set.archive ?? 0, clamp(Math.min(cpus * 3, byMemory("archive", 0.6)), 2, 192)),
|
||||
archiveDownloads: clamp(Math.max(16, cpus * 20), 16, 1000),
|
||||
render: set.render ?? clamp(Math.min(cpus * 0.15, byMemory("render", 0.15)), 2, 12),
|
||||
delivery: set.delivery ?? clamp(cpus * 0.25, 4, 16),
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@ import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import sharp from "sharp";
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||
import { describeFolder, isInitials, isTeam, lisbonDay, parseFolder, pickFixture, type FixtureCandidate } from "../src/archive/match.js";
|
||||
import { canonicalTeam, describeFolder, exhibitionName, isExhibition, isInitials, isTeam, lisbonDay, parseFolder, pickFixture, teamLabel, type FixtureCandidate } from "../src/archive/match.js";
|
||||
import { parseMultistatus } from "../src/archive/nextcloud.js";
|
||||
import { ArchiveService, localDirs } from "../src/archive/service.js";
|
||||
import { SecretBox } from "../src/delivery/secrets.js";
|
||||
@@ -171,12 +171,43 @@ describe("archive folder names", () => {
|
||||
expect(isTeam("SLB", { name: "Sporting Clube de Portugal", abbreviation: null, slug: "sporting" })).toBe(false);
|
||||
});
|
||||
|
||||
it("takes the only game of that competition and day when one side is named otherwise", () => {
|
||||
it("takes a game only when both sides are recognised, never with one guessed", () => {
|
||||
const t = (name: string) => ({ name, abbreviation: null, slug: name });
|
||||
const f = (id: string, home: string, away: string): FixtureCandidate => ({ id, startsAt: new Date("2026-10-03T17:00:00Z"), season: "20262027", round: null, competition: { externalId: "PO01" }, homeTeam: t(home), awayTeam: t(away) });
|
||||
const fixtures = [f("a", "Sporting Clube de Portugal", "Marítimo Madeira Andebol SAD"), f("b", "Sport Lisboa e Benfica", "FC Gaia")];
|
||||
expect(pickFixture(parseFolder("/2026_2027/Competições Nacionais/PO01/20261003 - SCP x Marítimo")!, fixtures)?.id).toBe("a");
|
||||
expect(pickFixture(parseFolder("/2026_2027/Competições Nacionais/PO01/20261003 - SCP x SLB")!, fixtures)).toBeNull();
|
||||
expect(pickFixture(parseFolder("/2026_2027/Competições Nacionais/PO01/20261003 - SCP x Desconhecido")!, fixtures)).toBeNull();
|
||||
});
|
||||
|
||||
it("never matches a legends' tournament or a charity game to a championship, nor a first team to its B side", () => {
|
||||
const t = (name: string) => ({ name, abbreviation: null, slug: name });
|
||||
const f = (id: string, day: string, home: string, away: string, season = "20252026"): FixtureCandidate => ({ id, startsAt: new Date(`${day}T17:00:00Z`), season, round: "2", competition: { externalId: "ligaportugalmeusuper" }, homeTeam: t(home), awayTeam: t(away) });
|
||||
const legends = parseFolder("/Liga Portugal Legends 2025-26/Dia 2/8. SL Benfica x SCU Torreense")!;
|
||||
expect(isExhibition(legends)).toBe(true);
|
||||
expect(exhibitionName(legends)).toBe("Liga Portugal Legends 2025-26");
|
||||
expect(pickFixture({ ...legends, day: "2026-03-10" }, [f("a", "2026-03-10", "SL Benfica", "SCU Torreense")])).toBeNull();
|
||||
expect(isTeam("SL Benfica", t("SL Benfica B"))).toBe(false);
|
||||
expect(isTeam("Benfica B", t("SL Benfica B"))).toBe(true);
|
||||
const game = parseFolder("/2025_2026/Liga/20260310 - SL Benfica x SCU Torreense")!;
|
||||
expect(pickFixture(game, [f("b", "2026-03-10", "SL Benfica B", "SCU Torreense")])).toBeNull();
|
||||
});
|
||||
|
||||
it("names teams without the date before them, and as the known team when one fits", () => {
|
||||
expect(teamLabel("01.23 Leixoes SC")).toBe("Leixoes SC");
|
||||
expect(teamLabel("02_ESTORIL PRAIA")).toBe("ESTORIL PRAIA");
|
||||
expect(teamLabel("10 (copiar).22 CD Tondela")).toBe("CD Tondela");
|
||||
expect(teamLabel("1 Gil Vicente")).toBe("Gil Vicente");
|
||||
expect(teamLabel("Sporting CP B")).toBe("Sporting CP B");
|
||||
const known = [
|
||||
{ name: "Sporting CP", abbreviation: "SCP", slug: "sporting-cp" },
|
||||
{ name: "U. Leiria", abbreviation: "UDL", slug: "u-leiria" },
|
||||
{ name: "SL Benfica B", abbreviation: "SLB B", slug: "benfica-b" },
|
||||
];
|
||||
expect(canonicalTeam("01 SCP", known)).toBe("Sporting CP");
|
||||
expect(canonicalTeam("06_SPORTING CP", known)).toBe("Sporting CP");
|
||||
expect(canonicalTeam("02.2024 Benfica B", known)).toBe("SL Benfica B");
|
||||
expect(canonicalTeam("09.2023 Leiria", known)).toBe("U. Leiria");
|
||||
});
|
||||
|
||||
it("picks the one fixture with those teams on that day", () => {
|
||||
|
||||
@@ -7,11 +7,11 @@ describe("capacity", () => {
|
||||
it("does more at once on a bigger container", () => {
|
||||
const small = planCapacity({}, { cpus: 4, memoryBytes: 8 * GB });
|
||||
const big = planCapacity({}, { cpus: 32, memoryBytes: 64 * GB });
|
||||
expect(small).toMatchObject({ faces: 2, ingest: 4, archive: 2, render: 2, delivery: 4 });
|
||||
expect(big).toMatchObject({ cpus: 32, faces: 14, ingest: 8, archive: 9, archiveBurst: 24, render: 4, delivery: 8 });
|
||||
expect(planCapacity({}, { cpus: 48, memoryBytes: 64 * GB })).toMatchObject({ faces: 21, archiveBurst: 36, archiveDownloads: 192 });
|
||||
expect(small).toMatchObject({ faces: 3, ingest: 4, archive: 2, render: 2, delivery: 4 });
|
||||
expect(big).toMatchObject({ cpus: 32, faces: 28, ingest: 8, archive: 9, archiveBurst: 91, render: 4, delivery: 8 });
|
||||
expect(planCapacity({}, { cpus: 48, memoryBytes: 64 * GB })).toMatchObject({ faces: 38, archiveBurst: 91, archiveDownloads: 960 });
|
||||
// A fixed ARCHIVE_CONCURRENCY never holds a backlog back; downloads run many at once even on a small machine.
|
||||
expect(planCapacity({ archive: 2 }, { cpus: 4, memoryBytes: 8 * GB })).toMatchObject({ archive: 2, archiveBurst: 3, archiveDownloads: 16 });
|
||||
expect(planCapacity({ archive: 2 }, { cpus: 4, memoryBytes: 8 * GB })).toMatchObject({ archive: 2, archiveBurst: 7, archiveDownloads: 80 });
|
||||
});
|
||||
|
||||
it("is held back by memory when cores are many and memory is short", () => {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { afterAll, beforeEach, describe, expect, it } from "vitest";
|
||||
import { createDb } from "../src/db.js";
|
||||
import { dropCrossSportSuggestions, eventSport, normSport, peopleSports } from "../src/faces/service.js";
|
||||
import { resetDb, seedUser } from "./helpers.js";
|
||||
|
||||
/** A footballer is never suggested at a handball game, nor a handball player at a football game. */
|
||||
describe("face suggestions keep to the event's sport", () => {
|
||||
const db = createDb(process.env.DATABASE_URL_TEST ?? "");
|
||||
afterAll(() => db.$disconnect());
|
||||
beforeEach(() => resetDb(db));
|
||||
|
||||
it("knows each person's sport by their squad, and takes away suggestions of another sport", async () => {
|
||||
const { org, user } = await seedUser(db, "[email protected]", { org: "fpa", role: "OWNER" });
|
||||
const orgId = org!.id;
|
||||
const football = await db.sportsTeam.create({ data: { provider: "LIGA", externalId: "est", sport: "futebol", name: "Estoril Praia", slug: "estoril" } });
|
||||
const handball = await db.sportsTeam.create({ data: { provider: "FPA", externalId: "abc", sport: "andebol", name: "ABC de Braga", slug: "abc" } });
|
||||
const xeka = await db.person.create({
|
||||
data: { organizationId: orgId, name: "Xeka", sportsPlayerId: (await db.sportsPlayer.create({ data: { teamId: football.id, season: "20262027", externalId: "x", name: "Xeka" } })).id },
|
||||
});
|
||||
const ana = await db.person.create({
|
||||
data: { organizationId: orgId, name: "Ana", sportsPlayerId: (await db.sportsPlayer.create({ data: { teamId: handball.id, season: "20262027", externalId: "a", name: "Ana" } })).id },
|
||||
});
|
||||
const typed = await db.person.create({ data: { organizationId: orgId, name: "Sem equipa" } });
|
||||
const at = new Date("2026-10-04T18:00:00Z");
|
||||
const game = await db.event.create({ data: { organizationId: orgId, home: "ABC de Braga", away: "CD Feirense", sport: "Andebol", startsAt: at, ingestFrom: at, ingestUntil: at, iptcTemplate: {}, createdById: user.id } });
|
||||
expect(await eventSport(db, game.id)).toBe("andebol");
|
||||
expect(normSport("Football")).toBe("futebol");
|
||||
const sports = await peopleSports(db, [xeka, ana, typed]);
|
||||
expect([sports.get(xeka.id), sports.get(ana.id), sports.get(typed.id)]).toEqual(["futebol", "andebol", undefined]);
|
||||
|
||||
const group = (personId: string) => db.faceGroup.create({ data: { organizationId: orgId, eventId: game.id, centroid: [1, 0], model: "m", size: 2, suggestedPersonId: personId, suggestionScore: 0.7 } });
|
||||
const [g1, g2, g3] = [await group(xeka.id), await group(ana.id), await group(typed.id)];
|
||||
expect(await dropCrossSportSuggestions(db)).toBe(1);
|
||||
const after = await db.faceGroup.findMany({ where: { id: { in: [g1.id, g2.id, g3.id] } }, orderBy: { createdAt: "asc" } });
|
||||
expect(after.map((g) => g.suggestedPersonId)).toEqual([null, ana.id, typed.id]);
|
||||
});
|
||||
});
|
||||
@@ -133,7 +133,12 @@ export function ArchiveView({ info }: { info: ArchiveInfo }) {
|
||||
</button>
|
||||
</span>
|
||||
);
|
||||
if (!ready) return <main className="wrap" aria-busy="true" />;
|
||||
if (!ready)
|
||||
return (
|
||||
<main className="wrap">
|
||||
<Loading />
|
||||
</main>
|
||||
);
|
||||
return (
|
||||
<>
|
||||
{owner && (
|
||||
@@ -249,6 +254,38 @@ function SignIn({ info, onDone }: { info: ArchiveInfo; onDone: (token: string, n
|
||||
|
||||
type Tab = "galleries" | "people" | "teams";
|
||||
|
||||
/**
|
||||
* What is shown while something loads: never a blank page. After a while it says so and offers to try again (a
|
||||
* big gallery, a busy server), with the way back always there.
|
||||
*/
|
||||
function Loading({ onBack, backLabel = "← Voltar", onRetry }: { onBack?: () => void; backLabel?: string; onRetry?: () => void }) {
|
||||
const [slow, setSlow] = useState(false);
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(() => setSlow(true), 8000);
|
||||
return () => clearTimeout(timer);
|
||||
}, []);
|
||||
return (
|
||||
<>
|
||||
{onBack && (
|
||||
<div className="toolbar">
|
||||
<button type="button" className="chip" onClick={onBack}>
|
||||
{backLabel}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
<div className="loading" role="status" aria-live="polite">
|
||||
<span className="spinner" aria-hidden="true" />
|
||||
<span>{slow ? "Está a demorar mais do que o costume…" : "A carregar…"}</span>
|
||||
{slow && onRetry && (
|
||||
<button type="button" className="linkish" onClick={onRetry}>
|
||||
Tentar outra vez
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** Where the viewer is: browsing, in a gallery, on a person's photos, or on "more of this face". */
|
||||
type View = { kind: "browse" } | { kind: "gallery"; id: string } | { kind: "person"; id: string } | { kind: "face"; id: string };
|
||||
|
||||
@@ -384,6 +421,7 @@ function Browse({ info, token, onExpired }: { info: ArchiveInfo; token: string;
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{list === null && <Loading />}
|
||||
{list?.length === 0 && <p className="empty">Nenhuma galeria partilhada contigo{q || team || player ? " com estes filtros" : ""}.</p>}
|
||||
<div className="cards">
|
||||
{list?.map((g) => (
|
||||
@@ -419,7 +457,7 @@ function Browse({ info, token, onExpired }: { info: ArchiveInfo; token: string;
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{!people && <p className="empty" aria-busy="true" />}
|
||||
{!people && <Loading />}
|
||||
{people && shownPeople.length === 0 && <p className="empty">{people.people.length ? "Ninguém com esse nome." : "Ainda não há pessoas identificadas nestas galerias. Abre uma foto e clica numa cara para encontrar mais fotos dela."}</p>}
|
||||
<ul className="people-grid">
|
||||
{shownPeople.map((p) => (
|
||||
@@ -440,7 +478,11 @@ function Browse({ info, token, onExpired }: { info: ArchiveInfo; token: string;
|
||||
|
||||
{tab === "teams" && (
|
||||
<ul className="archive-names">
|
||||
{!directory && <li className="empty" aria-busy="true" />}
|
||||
{!directory && (
|
||||
<li>
|
||||
<Loading />
|
||||
</li>
|
||||
)}
|
||||
{directory?.teams
|
||||
.filter((t) => fold(t.name).includes(fold(q.trim())))
|
||||
.map((t) => (
|
||||
@@ -526,13 +568,14 @@ function PhotosOf({
|
||||
const [index, setIndex] = useState<number | null>(null);
|
||||
const [error, setError] = useState(false);
|
||||
|
||||
const [attempt, setAttempt] = useState(0);
|
||||
useEffect(() => {
|
||||
const url = view.kind === "person" ? `/v1/archive/${info.id}/people/${view.id}` : `/v1/archive/${info.id}/faces/${view.id}/similar`;
|
||||
call<PhotosOfResult>(url, token).then(
|
||||
({ body }) => setData(body),
|
||||
(err) => (err instanceof Unauthorised ? onExpired() : setError(true)),
|
||||
);
|
||||
}, [info.id, view.kind, view.id, token, onExpired]);
|
||||
}, [info.id, view.kind, view.id, token, onExpired, attempt]);
|
||||
|
||||
const photos = useMemo(() => (data ? (only ? data.photos.filter((p) => p.level === only) : data.photos) : []), [data, only]);
|
||||
const counts = useMemo(() => {
|
||||
@@ -541,8 +584,23 @@ function PhotosOf({
|
||||
return c;
|
||||
}, [data]);
|
||||
|
||||
if (error) return <p className="empty">Não foi possível abrir esta pesquisa.</p>;
|
||||
if (!data) return <p className="empty" aria-busy="true" />;
|
||||
if (error)
|
||||
return (
|
||||
<>
|
||||
<div className="toolbar">
|
||||
<button type="button" className="chip" onClick={onBack}>
|
||||
← Voltar
|
||||
</button>
|
||||
</div>
|
||||
<p className="empty">
|
||||
Não foi possível abrir esta pesquisa.{" "}
|
||||
<button type="button" className="linkish" onClick={() => (setError(false), setAttempt((n) => n + 1))}>
|
||||
Tentar outra vez
|
||||
</button>
|
||||
</p>
|
||||
</>
|
||||
);
|
||||
if (!data) return <Loading onBack={onBack} onRetry={() => setAttempt((n) => n + 1)} />;
|
||||
const first = data.photos[0];
|
||||
const who = data.person;
|
||||
return (
|
||||
@@ -748,12 +806,13 @@ function Gallery({
|
||||
const [index, setIndex] = useState<number | null>(null);
|
||||
const [error, setError] = useState(false);
|
||||
|
||||
const [attempt, setAttempt] = useState(0);
|
||||
useEffect(() => {
|
||||
call<GalleryDetail>(`/v1/archive/galleries/${id}`, token).then(
|
||||
({ body }) => setG(body),
|
||||
(err) => (err instanceof Unauthorised ? onExpired() : setError(true)),
|
||||
);
|
||||
}, [id, token, onExpired]);
|
||||
}, [id, token, onExpired, attempt]);
|
||||
|
||||
// Who is in this gallery: named faces first (with a face to show), then names written on the photos.
|
||||
const people = useMemo(() => {
|
||||
@@ -769,8 +828,23 @@ function Gallery({
|
||||
}, [g]);
|
||||
const photos = useMemo(() => (g ? (only ? g.photos.filter((p) => (p.faces ?? []).some((f) => f.person?.id === only && f.level === "confirmed")) : g.photos) : []), [g, only]);
|
||||
|
||||
if (error) return <p className="empty">Esta galeria não está disponível para ti.</p>;
|
||||
if (!g) return <p className="empty" aria-busy="true" />;
|
||||
if (error)
|
||||
return (
|
||||
<>
|
||||
<div className="toolbar">
|
||||
<button type="button" className="chip" onClick={onBack}>
|
||||
← Galerias
|
||||
</button>
|
||||
</div>
|
||||
<p className="empty">
|
||||
Não foi possível abrir esta galeria.{" "}
|
||||
<button type="button" className="linkish" onClick={() => (setError(false), setAttempt((n) => n + 1))}>
|
||||
Tentar outra vez
|
||||
</button>
|
||||
</p>
|
||||
</>
|
||||
);
|
||||
if (!g) return <Loading onBack={onBack} backLabel="← Galerias" onRetry={() => setAttempt((n) => n + 1)} />;
|
||||
return (
|
||||
<>
|
||||
<div className="toolbar">
|
||||
|
||||
@@ -347,6 +347,31 @@ select {
|
||||
padding: 64px 0;
|
||||
color: var(--muted);
|
||||
}
|
||||
.loading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 64px 0;
|
||||
color: var(--muted);
|
||||
}
|
||||
.spinner {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border-radius: 50%;
|
||||
border: 2px solid currentColor;
|
||||
border-right-color: transparent;
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.spinner {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* Gallery */
|
||||
.gallery-head {
|
||||
|
||||
@@ -83,6 +83,24 @@ than none:
|
||||
move to the archive's own events, faces found again there; photos that were already in the live event (the same
|
||||
picture sent live) stay, and so do folders placed there by hand. Otherwise an event from the name (NAME) or named after the folder (FOLDER).
|
||||
|
||||
- Both teams must be recognised: a game with one side guessed (a nickname, a sponsor's name) is not matched. A first
|
||||
team is never its B side ("SL Benfica" is not "SL Benfica B").
|
||||
- Legends', veterans', charity, exhibition and tribute games, galas (`isExhibition`: "Liga Portugal Legends 2025-26")
|
||||
are games in no championship: never an official fixture; the tournament's folder is the event's competition.
|
||||
- Every check (on start, then every six hours, and after a season's calendar is read) makes every match but a manual
|
||||
one again with today's rules: a folder that no longer fits its official game moves to the right one or to an event
|
||||
of its own; a NAME event keeps its folder but takes the better names ("01.23 Leixões SC" → "Leixões SC", known
|
||||
teams by their official name). One folder failing never stops the rest.
|
||||
|
||||
**Teams in the viewer.** The directory and the team filter show each team once: without the date or number a folder
|
||||
put before it (`teamLabel`), and as the known team when exactly one fits (`canonicalTeam`: "SCP", "Sporting",
|
||||
"06_Sporting CP" → Sporting CP); filtering by it finds the galleries under every name it was written as.
|
||||
|
||||
**Faces keep to the sport.** A person known from a squad has that team's sport; a face is never suggested as someone
|
||||
of another sport than the event's (its own, its official game's, or its cloud's: Liga football, FPA handball).
|
||||
Suggestions made before that are taken away on the worker's start (`dropCrossSportSuggestions`); names confirmed by
|
||||
a person stay.
|
||||
|
||||
**Games and events are kept apart.** A game (FIXTURE/MANUAL: official; NAME: known only by its folder) is matched
|
||||
on competition, season, matchday, day and teams; an event (FOLDER: a gala, a session, a presentation, a training)
|
||||
is never given a game and reads no shirt numbers (`numberContext` is null for an event without an away side): its
|
||||
|
||||
Reference in new issue
Block a user