diff --git a/apps/api/src/archive/review.ts b/apps/api/src/archive/review.ts index 8fa3481..efb0cea 100644 --- a/apps/api/src/archive/review.ts +++ b/apps/api/src/archive/review.ts @@ -170,7 +170,7 @@ export async function registerArchiveReviewRoutes(app: FastifyInstance, deps: De row_number() OVER (PARTITION BY f.group_id ORDER BY f.sharpness DESC NULLS LAST, f.score DESC) AS rank FROM faces f JOIN cloud_files cf ON cf.photo_id = f.photo_id AND ${scope.sql} WHERE f.group_id = ANY(${ids}::uuid[]) - ) s WHERE rank <= 4` + ) s WHERE rank <= 8` : []; const photos = await db.photo.findMany({ where: { id: { in: [...new Set(samples.map((s) => s.photo_id))] } }, diff --git a/apps/api/src/faces/routes.ts b/apps/api/src/faces/routes.ts index e02aef5..3468c60 100644 --- a/apps/api/src/faces/routes.ts +++ b/apps/api/src/faces/routes.ts @@ -109,6 +109,45 @@ export async function registerFaceRoutes( return { groups: out, pending, unclear, available: deps.engineOnline ? deps.engineOnline() : true }; }); + /** Suggested faces across the library, one row per group, so an editor can clear them while others are selecting. */ + app.get("/v1/orgs/:orgId/face-review", { preHandler: authenticate }, async (req) => { + const { orgId } = OrgParams.parse(req.params); + await requireMembership(db, req, orgId, "INGESTER"); + const groups = await db.faceGroup.findMany({ + where: { organizationId: orgId, personId: null, ignoredAt: null, suggestedPersonId: { not: null } }, + orderBy: [{ suggestionScore: "desc" }, { size: "desc" }], + take: 80, + include: { + suggested: true, + event: { select: { home: true, away: true, startsAt: true } }, + faces: { + take: SAMPLES, + orderBy: [{ sharpness: { sort: "desc", nulls: "last" } }, { score: "desc" }], + select: { id: true, photoId: true, x0: true, y0: true, x1: true, y1: true, photo: { select: { width: true, height: true } } }, + }, + }, + }); + return { + groups: groups.map((g) => ({ + id: g.id, + eventId: g.eventId, + size: g.size, + suggestion: g.suggested && g.suggestionScore !== null ? { ...personOut(g.suggested)!, score: g.suggestionScore } : null, + event: { title: g.event.away ? `${g.event.home} x ${g.event.away}` : g.event.home, startsAt: g.event.startsAt }, + samples: g.faces.map((f) => ({ + faceId: f.id, + photoId: f.photoId, + x0: f.x0, + y0: f.y0, + x1: f.x1, + y1: f.y1, + aspect: f.photo.width && f.photo.height ? f.photo.width / f.photo.height : 1.5, + preview: signer.url(f.photoId, "preview"), + })), + })), + }; + }); + app.post("/v1/face-groups/:groupId/confirm", { preHandler: authenticate }, async (req) => { const { groupId } = GroupParams.parse(req.params); const body = ConfirmFaceGroup.parse(req.body); diff --git a/apps/api/src/faces/service.ts b/apps/api/src/faces/service.ts index d772d8b..0a50513 100644 --- a/apps/api/src/faces/service.ts +++ b/apps/api/src/faces/service.ts @@ -534,6 +534,15 @@ export class FaceService { const photoIds = (await db.face.findMany({ where: { groupId }, select: { photoId: true } })).map((f) => f.photoId); await this.nameConfirmedPhotos([...new Set(photoIds)]); await this.refreshSuggestions(group.eventId); + // The same person suggested in other games: their cards are read again with this face included, so confirming + // one pulls the rest together instead of leaving a separate guess in every event. + const others = await db.faceGroup.findMany({ + where: { suggestedPersonId: person.id, personId: null, ignoredAt: null, eventId: { not: group.eventId } }, + select: { eventId: true }, + distinct: ["eventId"], + take: 25, + }); + for (const other of others) await this.refreshSuggestions(other.eventId); this.deps.broadcaster.library(group.organizationId, { type: "faces.updated", eventId: group.eventId }); return person; } diff --git a/apps/api/src/sports/providers.ts b/apps/api/src/sports/providers.ts index 73b5b72..1f371de 100644 --- a/apps/api/src/sports/providers.ts +++ b/apps/api/src/sports/providers.ts @@ -111,11 +111,14 @@ const url = (...vs: unknown[]): string | null => { // --- Liga Portugal ------------------------------------------------------------------------------------------------ export const LIGA_COMPETITIONS = [ - { externalId: "ligaportugalbetclic", name: "Liga Portugal Betclic", aliases: ["Liga Portugal Betclic"] }, - { externalId: "ligaportugalmeusuper", name: "Liga Portugal Meu Super", aliases: ["Liga Portugal Meu Super", "Liga Portugal 2 Meu Super"] }, - { externalId: "allianzcup", name: "Allianz Cup", aliases: ["Allianz Cup"] }, + // The same two leagues, under every sponsor Liga has used. A 2022 folder is "bwin"; 2026 is "Betclic". + { externalId: "ligaportugalbetclic", name: "Liga Portugal Betclic", aliases: ["Liga Portugal Betclic", "Liga Portugal bwin", "Liga NOS"] }, + { externalId: "ligaportugalmeusuper", name: "Liga Portugal Meu Super", aliases: ["Liga Portugal Meu Super", "Liga Portugal 2 Meu Super", "Liga Portugal SABSEG", "LigaPro"] }, + { externalId: "allianzcup", name: "Allianz Cup", aliases: ["Allianz Cup", "Allianz CUP", "Taça da Liga", "Taca da Liga"] }, ] as const; +const foldComp = (s: string) => s.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/\s+/g, " ").trim(); + export class LigaProvider { static readonly BASE = "https://www.ligaportugal.pt/api/v1"; private static readonly HEADERS = { accept: "application/json", "accept-language": "pt-PT,pt;q=0.9", locale: "pt-PT", "x-client-platform": "web" }; @@ -219,7 +222,7 @@ export class LigaProvider { for (const day of days as { date?: string; fixtures?: Record[] }[]) { for (const f of day.fixtures ?? []) { const name = str(f.competitionName) ?? ""; - const comp = LIGA_COMPETITIONS.find((c) => (c.aliases as readonly string[]).includes(name)); + const comp = LIGA_COMPETITIONS.find((c) => c.aliases.some((a) => foldComp(a) === foldComp(name))); const home = ligaTeam(f.homeTeam); const away = ligaTeam(f.awayTeam); const when = str(f.matchDate) ?? str(f.fixtureDate) ?? day.date; diff --git a/apps/app/src/App.tsx b/apps/app/src/App.tsx index 60ec3b8..b22b843 100644 --- a/apps/app/src/App.tsx +++ b/apps/app/src/App.tsx @@ -5,6 +5,7 @@ import { t } from "./i18n.js"; import { ArchivePage } from "./pages/ArchivePage.js"; import { DevelopPage } from "./pages/DevelopPage.js"; import { DeliveryPage } from "./pages/DeliveryPage.js"; +import { FacesQueuePage } from "./pages/FacesQueuePage.js"; import { NumbersPage } from "./pages/NumbersPage.js"; import { PrintPage } from "./pages/PrintPage.js"; import { ShopPage } from "./pages/ShopPage.js"; @@ -33,6 +34,7 @@ function Gate() { } /> } /> } /> + } /> } /> } /> } /> diff --git a/apps/app/src/i18n.ts b/apps/app/src/i18n.ts index 92e0a9b..abc1830 100644 --- a/apps/app/src/i18n.ts +++ b/apps/app/src/i18n.ts @@ -31,6 +31,8 @@ export const t = { develop: "Revelar", metadata: "Metadados", archiveNav: "Arquivo", + facesNav: "Caras", + numbersNav: "Camisolas", delivery: "Entregar", soon: "Em breve", events: "Eventos", diff --git a/apps/app/src/pages/FacesQueuePage.tsx b/apps/app/src/pages/FacesQueuePage.tsx new file mode 100644 index 0000000..5d75cfc --- /dev/null +++ b/apps/app/src/pages/FacesQueuePage.tsx @@ -0,0 +1,114 @@ +import { useCallback, useEffect, useState } from "react"; +import { Link } from "react-router"; +import { useAuth } from "../auth.js"; +import { FaceCrop } from "../library/FacesView.js"; +import { t } from "../i18n.js"; +import { PageHeader } from "./Shell.js"; + +interface Sample { + faceId: string; + x0: number; + y0: number; + x1: number; + y1: number; + aspect: number; + preview: string; +} +interface Row { + id: string; + eventId: string; + size: number; + suggestion: { id: string; name: string; club: string | null; number: string | null; score: number } | null; + event: { title: string; startsAt: string }; + samples: Sample[]; +} + +/** + * Faces waiting across the library, grouped by the person they seem to be. Confirming one names every game of + * that person on this page and teaches the next match. Shirt numbers are checked on Camisolas. + */ +export function FacesQueuePage() { + const { api, organization } = useAuth(); + const orgId = organization?.id ?? ""; + const [rows, setRows] = useState(null); + const [busy, setBusy] = useState(null); + const [open, setOpen] = useState(null); + const [at, setAt] = useState(0); + + const load = useCallback(async () => { + if (!orgId) return; + const body = await api.request<{ groups: Row[] }>("GET", `/v1/orgs/${orgId}/face-review`); + setRows(body.groups); + }, [api, orgId]); + useEffect(() => { + void load().catch(() => setRows([])); + }, [load]); + + const piles = new Map(); + for (const row of rows ?? []) { + const key = row.suggestion?.id ?? row.id; + piles.set(key, [...(piles.get(key) ?? []), row]); + } + + const confirm = async (pile: Row[]) => { + const personId = pile[0]?.suggestion?.id; + if (!personId) return; + setBusy(personId); + try { + for (const row of pile) await api.request("POST", `/v1/face-groups/${row.id}/confirm`, { personId }); + setRows((cur) => cur?.filter((r) => !pile.some((p) => p.id === r.id)) ?? null); + } finally { + setBusy(null); + } + }; + + return ( +
+ +

+ As caras por confirmar, juntas por pessoa. As camisolas ensinam-se em {t.numbersNav}. +

+
+ {rows === null &&

A carregar…

} + {rows?.length === 0 &&

Nada por confirmar.

} + {[...piles.values()].map((pile) => { + const who = pile[0]!.suggestion; + const faces = pile.flatMap((r) => r.samples); + return ( +
+ +
+

{who?.name}

+

+ {[who?.number && `nº ${who.number}`, who?.club, `${pile.reduce((n, r) => n + r.size, 0)} fotos`, pile.length > 1 ? `${pile.length} jogos` : pile[0]!.event.title] + .filter(Boolean) + .join(" · ")} +

+
+ +
+ ); + })} +
+ {open && open[at] && ( +
setOpen(null)}> + + e.stopPropagation()}> + + + +
+ )} +
+ ); +} diff --git a/apps/app/src/pages/Shell.tsx b/apps/app/src/pages/Shell.tsx index a927a79..22f2688 100644 --- a/apps/app/src/pages/Shell.tsx +++ b/apps/app/src/pages/Shell.tsx @@ -97,6 +97,18 @@ export function Shell() { {t.archiveNav} + + + {t.facesNav} + + + + {t.numbersNav} + )} diff --git a/apps/site/src/app/arquivo/[id]/Review.tsx b/apps/site/src/app/arquivo/[id]/Review.tsx index 5fdb2b4..dbd0137 100644 --- a/apps/site/src/app/arquivo/[id]/Review.tsx +++ b/apps/site/src/app/arquivo/[id]/Review.tsx @@ -80,7 +80,14 @@ export function Review({ sourceId, token, me, person, onPerson, onExpired, onCha [sourceId, token, status, onExpired, onChanged], ); - const toggle = (id: string) => setSelected((s) => (s.has(id) ? new Set([...s].filter((x) => x !== id)) : new Set([...s, id]))); + const togglePile = (pile: ReviewGroup[]) => + setSelected((s) => { + const on = pile.every((g) => s.has(g.id)); + const next = new Set(s); + for (const g of pile) if (on) next.delete(g.id); + else next.add(g.id); + return next; + }); const chosen = data?.people.find((p) => p.id === person) ?? null; const ids = [...selected]; @@ -151,9 +158,19 @@ export function Review({ sourceId, token, me, person, onPerson, onExpired, onCha {!data && !error && } {data && data.groups.length === 0 &&

{status === "suggested" ? "Nada por confirmar aqui. Bom trabalho." : "Nada nesta lista."}

}
- {data?.groups.map((g) => ( - toggle(g.id)} onAct={(a, p) => void act([g.id], a, p)} searchPeople={searchPeople} /> - ))} + {data && + piles(data.groups, status).map((pile) => ( + g.id).join("-")} + groups={pile} + status={status} + busy={pile.some((g) => busy.has(g.id))} + selected={pile.every((g) => selected.has(g.id))} + onToggle={() => togglePile(pile)} + onAct={(a, p) => void act(pile.map((g) => g.id), a, p)} + searchPeople={searchPeople} + /> + ))}
@@ -237,8 +254,26 @@ function NameSearch({ placeholder, searchPeople, onPick }: { placeholder: string ); } +/** The same person in several games is one card: confirming once names all of them and teaches the next match. */ +function piles(groups: ReviewGroup[], status: ReviewStatus): ReviewGroup[][] { + if (status !== "suggested" && status !== "confirmed") return groups.map((g) => [g]); + const order: string[] = []; + const by = new Map(); + for (const g of groups) { + const who = status === "confirmed" ? g.person : g.suggested; + const key = who?.id ?? g.id; + const list = by.get(key); + if (list) list.push(g); + else { + by.set(key, [g]); + order.push(key); + } + } + return order.map((key) => by.get(key)!); +} + function Card({ - g, + groups, status, busy, selected, @@ -246,7 +281,7 @@ function Card({ onAct, searchPeople, }: { - g: ReviewGroup; + groups: ReviewGroup[]; status: ReviewStatus; busy: boolean; selected: boolean; @@ -254,8 +289,12 @@ function Card({ onAct: (a: Action, personId?: string) => void; searchPeople: (q: string) => Promise; }) { + const g = groups[0]!; const who = g.person ?? g.suggested; - const [first, ...rest] = g.faces; + const faces = groups.flatMap((item) => item.faces); + const photos = groups.reduce((n, item) => n + item.photos, 0); + const [open, setOpen] = useState(null); + const [first, ...rest] = faces; const onKey = (e: React.KeyboardEvent) => { if (busy || e.target instanceof HTMLInputElement) return; const k = e.key.toLowerCase(); @@ -268,9 +307,9 @@ function Card({ }; return (
- )} + {open !== null && faces[open] && ( +
setOpen(null)}> + + + e.stopPropagation()}> + + + +
+ )}
); } diff --git a/apps/site/src/app/arquivo/[id]/archive.css b/apps/site/src/app/arquivo/[id]/archive.css index 9c1b818..4f43655 100644 --- a/apps/site/src/app/arquivo/[id]/archive.css +++ b/apps/site/src/app/arquivo/[id]/archive.css @@ -1651,6 +1651,33 @@ font-size: 12px; color: var(--muted); } +.arq-lightbox { + position: fixed; + inset: 0; + z-index: 40; + display: flex; + align-items: center; + justify-content: center; + gap: 16px; + padding: 24px; + background: rgba(0, 0, 0, 0.86); +} +.arq-lightbox-nav, +.arq-lightbox-x { + width: 48px; + height: 48px; + border: 0; + border-radius: 999px; + background: #fff; + color: #111; + font-size: 28px; + line-height: 1; +} +.arq-lightbox-x { + position: absolute; + top: 16px; + right: 16px; +} .arq-ractions { display: grid; grid-auto-flow: column;