From cb2b887a48d1cc4bf02b79cec6aa399f19c69aed Mon Sep 17 00:00:00 2001 From: spark Date: Fri, 27 Nov 2026 19:08:09 +0000 Subject: [PATCH] Add a Cloud W17 destination beside Cloud M19 for the women's under-17 games. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It uses the organisation's existing FPA Nextcloud account and sends into Seleções Nacionais/W17, only when the photographer picks it. --- apps/api/src/delivery/fpa-m19.ts | 34 +++++++++++++++++++++----- apps/api/src/faces/selection.test.ts | 1 + apps/api/src/server.ts | 3 ++- apps/api/src/worker.ts | 3 ++- apps/app/src/library/TargetForm.tsx | 7 ++++++ docs/ARCHITECTURE.md | 3 ++- packages/metadata/src/metadata.test.ts | 15 ++++++++++++ packages/metadata/src/paths.ts | 5 ++++ 8 files changed, 62 insertions(+), 9 deletions(-) diff --git a/apps/api/src/delivery/fpa-m19.ts b/apps/api/src/delivery/fpa-m19.ts index 00538b4..a4665f4 100644 --- a/apps/api/src/delivery/fpa-m19.ts +++ b/apps/api/src/delivery/fpa-m19.ts @@ -4,13 +4,19 @@ import type { Db } from "../db.js"; /** The destination photographers pick to send an under-19 national game to the FPA cloud. */ export const CLOUD_M19_TARGET = "Cloud M19"; +/** The same kind of destination for the women's under-17 side. */ +export const CLOUD_W17_TARGET = "Cloud W17"; + /** * One Nextcloud destination per organisation that already delivers club games to cloud.photoreport.pt. - * Same account and file name as that destination; the folder is Seleções Nacionais/M19. + * Same account and file name as that destination; the folder is under Seleções Nacionais. * It does not send on arrival: the photographer chooses it for this game. * Returns how many destinations were created. */ -export async function ensureCloudM19Target(db: Db): Promise { +async function ensureNationalCloudTarget( + db: Db, + target: { name: string; folder: string; fileName: string }, +): Promise { const sources = await db.deliveryTarget.findMany({ where: { kind: "NEXTCLOUD", @@ -31,21 +37,21 @@ export async function ensureCloudM19Target(db: Db): Promise { if (seen.has(source.organizationId)) continue; seen.add(source.organizationId); const exists = await db.deliveryTarget.findUnique({ - where: { organizationId_name: { organizationId: source.organizationId, name: CLOUD_M19_TARGET } }, + where: { organizationId_name: { organizationId: source.organizationId, name: target.name } }, select: { id: true }, }); if (exists) continue; await db.deliveryTarget.create({ data: { organizationId: source.organizationId, - name: CLOUD_M19_TARGET, + name: target.name, kind: source.kind, baseUrl: source.baseUrl, username: source.username, secretEnc: source.secretEnc, hostFingerprint: source.hostFingerprint, - folderTemplate: DESTINATION_EXAMPLES.fpaM19.folder, - fileNameTemplate: source.fileNameTemplate || DESTINATION_EXAMPLES.fpaM19.fileName, + folderTemplate: target.folder, + fileNameTemplate: source.fileNameTemplate || target.fileName, longEdge: source.longEdge, jpegQuality: source.jpegQuality, sharpen: source.sharpen, @@ -64,3 +70,19 @@ export async function ensureCloudM19Target(db: Db): Promise { } return created; } + +export function ensureCloudM19Target(db: Db): Promise { + return ensureNationalCloudTarget(db, { + name: CLOUD_M19_TARGET, + folder: DESTINATION_EXAMPLES.fpaM19.folder, + fileName: DESTINATION_EXAMPLES.fpaM19.fileName, + }); +} + +export function ensureCloudW17Target(db: Db): Promise { + return ensureNationalCloudTarget(db, { + name: CLOUD_W17_TARGET, + folder: DESTINATION_EXAMPLES.fpaW17.folder, + fileName: DESTINATION_EXAMPLES.fpaW17.fileName, + }); +} diff --git a/apps/api/src/faces/selection.test.ts b/apps/api/src/faces/selection.test.ts index cf5195c..882de63 100644 --- a/apps/api/src/faces/selection.test.ts +++ b/apps/api/src/faces/selection.test.ts @@ -17,6 +17,7 @@ describe("selectionKey", () => { expect(selectionKey(["Seleção Nacional sub-19 Masculina"])).toBe("m19"); expect(selectionKey(["Portugal", "Espanha", "sub-19"])).toBe("m19"); expect(selectionKey(["Seleção Nacional sub-19 feminina"])).toBe("w19"); + expect(selectionKey(["/FPA/Fotos/2026_2027/Seleções Nacionais/W17/20261127 - POR x ITA"])).toBe("w17"); }); it("names no team for a club game, a gala, or a gathering", () => { diff --git a/apps/api/src/server.ts b/apps/api/src/server.ts index d26baf1..c2c8192 100644 --- a/apps/api/src/server.ts +++ b/apps/api/src/server.ts @@ -1,4 +1,4 @@ -import { ensureCloudM19Target } from "./delivery/fpa-m19.js"; +import { ensureCloudM19Target, ensureCloudW17Target } from "./delivery/fpa-m19.js"; import { preferIpv4 } from "./lib/prefer-ipv4.js"; import { buildApp, reporterFor } from "./app.js"; import { loadConfig } from "./config.js"; @@ -21,6 +21,7 @@ process.on("SIGTERM", () => void shutdown("SIGTERM")); process.on("SIGINT", () => void shutdown("SIGINT")); ensureCloudM19Target(db).catch((err) => app.log.warn({ err }, "delivery: Cloud M19 profile not created")); +ensureCloudW17Target(db).catch((err) => app.log.warn({ err }, "delivery: Cloud W17 profile not created")); try { await app.listen({ port: config.PORT, host: "0.0.0.0" }); diff --git a/apps/api/src/worker.ts b/apps/api/src/worker.ts index 6435f69..b9decdb 100644 --- a/apps/api/src/worker.ts +++ b/apps/api/src/worker.ts @@ -16,7 +16,7 @@ import { RenderPool, RenderProcess } from "./develop/engine.js"; import { DevelopService, RenderWorker } from "./develop/service.js"; import { FaceProcess, GrowingFacePool } from "./faces/process.js"; import { AutopilotService, AutopilotWorker } from "./autopilot/service.js"; -import { ensureCloudM19Target } from "./delivery/fpa-m19.js"; +import { ensureCloudM19Target, ensureCloudW17Target } from "./delivery/fpa-m19.js"; import { jogaClientFromConfig } from "./sports/joga.js"; import { SportsService, SportsWorker } from "./sports/service.js"; import { ArchiveService, ArchiveWorker, localDirs } from "./archive/service.js"; @@ -177,6 +177,7 @@ const sports = config.SPORTS_SYNC === "on" : undefined; ensureCloudM19Target(db).catch((err) => log.warn({ err }, "delivery: Cloud M19 profile not created")); +ensureCloudW17Target(db).catch((err) => log.warn({ err }, "delivery: Cloud W17 profile not created")); scanner.start(); if (secrets) archive.start(); autopilot.start(); diff --git a/apps/app/src/library/TargetForm.tsx b/apps/app/src/library/TargetForm.tsx index 81ffb87..228548a 100644 --- a/apps/app/src/library/TargetForm.tsx +++ b/apps/app/src/library/TargetForm.tsx @@ -139,6 +139,13 @@ const PRESETS = { longEdge: 4000, ...DESTINATION_EXAMPLES.fpaM19, }, + fpaW17: { + label: "Cloud W17", + kind: "NEXTCLOUD", + baseUrl: "https://cloud.photoreport.pt", + longEdge: 4000, + ...DESTINATION_EXAMPLES.fpaW17, + }, liga: { label: "Estrutura Liga", kind: "NEXTCLOUD", diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 718b155..131d25d 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -342,7 +342,8 @@ every 6 hours (`SPORTS_SYNC=off` turns it off). It is shared by every organisati seed when that team is still empty. Those friendlies are fixtures (`m19-por-esp-20261105`, `m19-esp-por-20261107`) so picking the game links that plantel, not the senior one. A folder or title that says sub-19 / M19 (not "Encontro Nacional") is that age group. Cloud delivery for these games is the - destination "Cloud M19" (`/FPA/Fotos/{season}/Seleções Nacionais/M19/…`), created from the organisation's + destination "Cloud M19" (`/FPA/Fotos/{season}/Seleções Nacionais/M19/…`) and "Cloud W17" + (`…/Seleções Nacionais/W17/…`), each created from the organisation's existing FPA Nextcloud account and never sent on arrival. FPA licence or an older EHF club photo fills gaps. People and reference faces are created when the event syncs those teams (`POST …/squads/sync`), not on every sports refresh. Example match: Portugal–Switzerland `202811130101002`. diff --git a/packages/metadata/src/metadata.test.ts b/packages/metadata/src/metadata.test.ts index 756a567..686f744 100644 --- a/packages/metadata/src/metadata.test.ts +++ b/packages/metadata/src/metadata.test.ts @@ -238,6 +238,21 @@ describe("delivery paths", () => { expect(renderFileName(DESTINATION_EXAMPLES.fpaM19.fileName, { ...m19, n: 3 }, "R1_0003.JPG")).toBe("PS_POR x ESP_3.jpg"); }); + it("matches the women's under-17 cloud folder", () => { + const w17 = buildVars({ + home: "Portugal", + away: "Itália", + homeShort: "POR", + awayShort: "ITA", + competition: "W17 EHF EURO", + startsAt: new Date("2026-11-27T19:00:00Z"), + }); + expect(renderFolder(DESTINATION_EXAMPLES.fpaW17.folder, w17)).toBe( + "/FPA/Fotos/2026_2027/Seleções Nacionais/W17/20261127 - POR x ITA/", + ); + expect(renderFileName(DESTINATION_EXAMPLES.fpaW17.fileName, { ...w17, n: 1 }, "R1_0001.JPG")).toBe("PS_POR x ITA_1.jpg"); + }); + it("matches the Liga folder and keeps the camera name", () => { const liga = buildVars({ home: "Casa Pia", away: "Sporting", round: 1, matchNumber: 1, startsAt: new Date("2025-08-09T18:00:00Z") }); expect(renderFolder(DESTINATION_EXAMPLES.liga.folder, liga)).toBe("/LPBetclic 25-26/Jornada 1/1. Casa Pia x Sporting/"); diff --git a/packages/metadata/src/paths.ts b/packages/metadata/src/paths.ts index 6bda5e8..0c62022 100644 --- a/packages/metadata/src/paths.ts +++ b/packages/metadata/src/paths.ts @@ -82,6 +82,11 @@ export const DESTINATION_EXAMPLES = { folder: "/FPA/Fotos/{season}/Seleções Nacionais/M19/{dateCompact} - {homeShort} x {awayShort}/", fileName: "PS_{homeShort} x {awayShort}_{n}.jpg", }, + /** Women's under-17. Same account as the club cloud; its own folder under Seleções Nacionais. */ + fpaW17: { + folder: "/FPA/Fotos/{season}/Seleções Nacionais/W17/{dateCompact} - {homeShort} x {awayShort}/", + fileName: "PS_{homeShort} x {awayShort}_{n}.jpg", + }, liga: { folder: "/LPBetclic {seasonShort}/Jornada {round}/{matchNumber}. {home} x {away}/", fileName: "{originalName}",