Files
photoreport/docs/archive.md
T
sparkandClaude Opus 5.5 303aedef80
ci / rust (push) Successful in 4m19s
ci / typescript (push) Successful in 7m38s
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
2026-10-15 03:49:08 +01:00

12 KiB

Archive (Arquivo)

Photos that live on a Nextcloud (the FPA archive on cloud.photoreport.pt, the Liga's cloud) indexed into the library: search by game, team and player, faces, galleries. The originals stay on the cloud; the library keeps a 2048 px preview (with the file's metadata) and a link back.

Connecting a cloud

App → Arquivo → "Ligar uma cloud": name, Nextcloud address, folder (from the account's root, e.g. /FPA/Fotos). The API starts Nextcloud's login flow v2 (POST {base}/index.php/login/v2); the person opens the returned page, signs in to the cloud and authorises. The app polls GET /v1/cloud-sources/:id, which polls the cloud; the app password it receives is sealed with DELIVERY_SECRET_KEY (cloud_sources.secret_enc). The account password never reaches PhotoReport. A revoked app password puts the source back to LOGIN ("Autorizar de novo").

Walking and indexing (worker)

  • ArchiveWorker (apps/api/src/archive/service.ts) walks each source every 6 h (or on "Analisar agora"): WebDAV PROPFIND depth 1 per folder, with Nextcloud's oc:fileid and etags. A folder whose etag has not changed is not read again (etags change up the tree), so a re-walk of an unchanged archive is one request.
  • Folders are keyed by file id (renames and moves keep their match). Images (.jpg) become cloud_files (PENDING); removed ones and removed sub-folders are dropped (the photos stay in the library).
  • Indexing (as many at once as the container's CPUs and memory allow, fewer while live work keeps it busy; see lib/capacity.ts), newest season first: download to a temp file, sha256, 2048 px preview with metadata, then the normal ingest as source CLOUD (originalStored = false, no autopilot, no rename). The same picture already in the library is linked, not duplicated. Faces run as for any photo.
  • Each claim is shared between the clouds with pending images, so a big newer archive (Liga) never starves another (FPA); inside a cloud, newest season first.
  • WebDAV through Nextcloud's PHP is the slow part of a big first import (the CPUs sit idle). With the cloud's data folder mounted read-only on the worker, ARCHIVE_LOCAL_DIRS reads the files from disk instead: https://cloud.photoreport.pt/FPA=/mnt/nextcloud/<owner>/files/FPA (comma-separated; the folder as the connected account sees it = where it is on disk). A file not there, or of another size than the walk saw, is downloaded as before; deliveries and the 100% view read from the mount too.
  • The editor's 100% view (GET /v1/photos/:id/original) and deliveries read the original from the cloud.

Matching galleries to games

archive/match.ts reads the place and name of each folder with images:

  • FPA: …/2025_2026/Competições Nacionais/PO01/20250913 - SCP x ABC → season, competition code, day, teams.

  • Liga: /LPBetclic 26-27/Jornada 5/03. Sporting CP x SC Braga → competition, season, matchday, teams.

  • Competition codes however written: PO01, PO-09, PO_09, PO01_2024_25, PO01 - Campeonato Betclic, Andebol 1; matchdays in the name (1ª J - FCG x VFC, J12 - GAIA x ALA).

  • A game's parts (1P, 2P, Aquecimento, 7M, 02 - Primeira Parte, Intervalo, Cerimónia, Analog/05510, a photographer's M4 - ICONSPORT) are the game: one event, the part shown as the gallery's section.

  • A dated session (20241118 - Sessão, 20241229 - Estudio): its folders are athletes (7 - Bebiana Sabino, Diogo Rema, tec - Renata Pereira). One event for the session; the athlete's name goes on the photos' players (search by player, "Atletas" on the viewer).

  • National teams: codes and English names become countries in Portuguese (SWE x POR → Suécia x Portugal) under a national team's folder or with Portugal on one side (so MAR x SCP stays Marítimo).

  • Not a game (a training, a day of an event): one event per occasion, named with the folder above when its own name says little (Encontro Nacional sub-14 - Externo · Dia 2). A dated folder with one name (20241105 - Treino) is never read as a club; A - B is two teams only after a date or a game's number.

Teams match by abbreviation, slug, name or close name (sameTeam); a game not found among the fixtures is named with the clubs' names when its initials name exactly one known club (SLB → SL Benfica). Every walk reads the galleries matched by name again (rematch) and puts right what is now understood better. One fixture found → the game's archived event (the archive's own, with both squads: archived events stay out of the day's list and never catch FTP photos).

The archive never adds to an event of the library (one photographed live), not even for the same official game: a wrong match must never put photos in an event someone is working on. Safeguards, because a wrong game is worse than none:

  • Only a dated folder, or one placed in its competition, season and matchday (LPBetclic 26-27/Jornada 5), is matched to an official game; a season, month or matchday alone is not (one club's month folder only when that month's game against the club above is the only one).

  • A reserve, youth or women's side in the name or the path (B, Sub-23, Feminino, Juniores, Revelação) never matches the first team's game.

  • Name events join only other archive events of the same day (never by the folder's date in the cloud, never an official game's).

  • Never a day still to come: fixtures not yet played are never candidates; a folder date in the future is read the other way when that makes sense (23.09.28 → 28 Sep 2023) or ignored; a name event is never dated ahead.

  • The photos' own day (captureDay: the Lisbon day of the camera time of most indexed photos, 3+ and 60%+) dates a folder whose name has no day, both to find its game and to date its event. A date in the folder's name always wins over the cameras (their clocks can be wrong).

  • Every walk, and on the worker's start for all clouds (verifyAll), each FIXTURE gallery is checked: an event still to come, or (the folder's name giving no day) another day than its photos were taken, takes it off that game for good, to an event of the photos' own day.

  • Before a photo of a FIXTURE folder is added, its capture day is checked against the game: more than 36 h apart and the folder is taken off the game for good (fixture_rejected), its photos moving to an event of its own.

  • On start, the worker takes out of live events every folder put there before (leaveLiveEvents): their photos 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 people are known by their face only. Arquivo → galleries: "Jogos oficiais", "Jogos por confirmar" (NAME), "Eventos" (FOLDER), "Todas"; "Escolher jogo" picks the official game and moves the photos.

Past seasons' calendars. The live refresh only keeps the current season. When the archive meets a folder of another season it reads that season's calendar once: Liga Portugal's month by month (importLigaSeason, awaited), the FPA's national games club by club (importFpaSeason: the portal's getJogosClubeEpocaEscalao for every level of each club, starting from today's agenda and following every club met, regional associations' games left out). The FPA's is slow on purpose (one portal page at a time), so it runs in the background, one season at a time, in the worker only; when it brings games, every gallery is matched again (verifyAll). A season counts as read with 300+ played games.

Viewers (site)

  • Each archive can wear its owner's look (cloud_sources.look): liga (Liga Portugal: night blue, orange, condensed capitals) or fpa (Federação de Andebol: light grey, red bar, Open Sans capitals); none is PhotoReport's. Set from the source's name or folder when connected, changed in the app (Arquivo → "Aspeto do site"). Colours and type only, no marks or logos of theirs (globals.css, [data-look]).

https://events.photoreport.pt/arquivo/<source id> (any site domain works; VITE_ARCHIVE_URL in the app sets the link it shows). The viewer signs in with their own account on that cloud (login flow v2 again). The API reads what is shared with them (OCS shared_with_me, user and group shares), revokes that app password at once, and gives the page a 12 h signed session (Authorization: Archive <token>) listing the archive folders shared with them; everything below a shared folder is visible. The account that indexes the source, or a share of its root or a folder above it, sees all of it. Galleries, a team list and a player list (from the photos' players) search within what they may see; originals open on the cloud itself (/f/<fileid>).

People and faces (viewers too)

archive/people.ts: "Pessoas" lists who appears in the viewer's galleries (named face groups, or suggested), with their reference photo or sharpest face, by club. A person's page has every photo of them the viewer may see: Identificado (named), Provável (suggested for that face group), Parecido (an unnamed face group whose centroid is like theirs, with how alike). Every face in a photo is boxed and clickable: "more of this face" compares its group's centroid with the face groups of the visible galleries (per-event groups, so a few thousand centroids, never every face). Nothing outside the folders shared with the viewer is compared or shown.

Disk

Each archive photo keeps about 1.6 MB on the server (the 2048 px preview with its metadata, the preview shown and the thumbnail). The Arquivo page shows the disk's free space and what the photos still to index will take; the worker stops indexing while less than ARCHIVE_MIN_FREE_GB (default 25) is free and resumes by itself.