From 56c115933c188462923c566f2e8a56414235c902 Mon Sep 17 00:00:00 2001 From: spark Date: Thu, 26 Nov 2026 22:07:12 +0000 Subject: [PATCH 1/2] Do not fail a ZeroZero delivery when the account cannot publish. A photographer login may upload and still get 403 on photo-sync. The file is already on the desk, so that refusal is not a failed delivery. --- apps/api/src/delivery/zerozero.test.ts | 11 +++-------- apps/api/src/delivery/zerozero.ts | 3 +++ docs/ARCHITECTURE.md | 3 ++- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/apps/api/src/delivery/zerozero.test.ts b/apps/api/src/delivery/zerozero.test.ts index f8bd6ae..ec2d513 100644 --- a/apps/api/src/delivery/zerozero.test.ts +++ b/apps/api/src/delivery/zerozero.test.ts @@ -123,21 +123,16 @@ describe("zerozero publish", () => { expect((err as TransportError).transient).toBe(true); }); - it("does not retry when neither publish route accepts the account", async () => { + it("keeps the upload when the account is not allowed to publish", async () => { const calls: string[] = []; const client = new ZerozeroClient( { username: "kapta", password: "zz-pass" }, desk((pathname) => { calls.push(pathname); - return Response.json({ error: "forbidden" }, { status: 403 }); + return Response.json({ error: "Insufficient permissions" }, { status: 403 }); }), ); - const err = await client.publish("12627743", "img-9").then( - () => null, - (error: unknown) => error, - ); - expect(err).toBeInstanceOf(TransportError); - expect((err as TransportError).transient).toBe(false); + await client.publish("12627743", "img-9"); expect(calls).toEqual(["/api/photo-sync/img-9", "/api/photo-sync/match/12627743"]); }); }); diff --git a/apps/api/src/delivery/zerozero.ts b/apps/api/src/delivery/zerozero.ts index 8b6d73b..d3cc0de 100644 --- a/apps/api/src/delivery/zerozero.ts +++ b/apps/api/src/delivery/zerozero.ts @@ -283,6 +283,9 @@ export class ZerozeroClient { } } const match = await this.postApi(`/photo-sync/match/${encodeURIComponent(gameId)}`, PUBLISH_TIMEOUT_MS); + // A photographer account may upload but not publish ("Insufficient permissions"). The file is already on + // the desk; failing the delivery here only blocks the queue. The desk publishes those itself. + if (match.status === 403) return; const ours = placeholder ? null : imageId; this.assertPublished(match, ours); } diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index e61d090..8fbe32d 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -477,7 +477,8 @@ The same queue also delivers to SFTP, FTP/FTPS and Dropbox (`delivery/transports author (`artist`: the photographer's name from the IPTC creator). The upload only reaches the photographer's desk. The public game shows the photo after publish: `POST /api/photo-sync/`, or `POST /api/photo-sync/match/` when the desk has no single-image publish (the same call as - "Sincronizar com zerozero"). A delivery is done only after that call succeeds. The "folder" is the game: + "Sincronizar com zerozero"). A photographer account that is refused (403) still counts as delivered: the file + is on the desk, and that account cannot publish. Any other publish failure fails the delivery. The "folder" is the game: chosen for the event by pasting the game's link (kept in `events.zerozero_game_id`), or found among the desk's upcoming games by both teams and kick-off within 3 hours. The delivered item's remote path is `/` (`DELETE /api/images/` takes it back). From 0a845f8bc69b70eeb6c05dedde4b74886d23a422 Mon Sep 17 00:00:00 2001 From: spark Date: Thu, 26 Nov 2026 22:20:55 +0000 Subject: [PATCH 2/2] Sign in to ZeroZero again when publish returns 403. A stale desk session answers Insufficient permissions instead of 401. One fresh login is tried before that refusal is accepted. --- apps/api/src/delivery/zerozero.test.ts | 27 ++++++++++++++++++++++++-- apps/api/src/delivery/zerozero.ts | 19 +++++++++++++++++- docs/ARCHITECTURE.md | 5 +++-- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/apps/api/src/delivery/zerozero.test.ts b/apps/api/src/delivery/zerozero.test.ts index ec2d513..101a95b 100644 --- a/apps/api/src/delivery/zerozero.test.ts +++ b/apps/api/src/delivery/zerozero.test.ts @@ -79,7 +79,25 @@ describe("zerozero publish", () => { }), ); await client.publish("12627743", "img-9"); - expect(calls).toEqual(["/api/photo-sync/img-9", "/api/photo-sync/match/12627743"]); + expect(calls).toEqual(["/api/photo-sync/img-9", "/api/photo-sync/img-9", "/api/photo-sync/match/12627743"]); + }); + + it("signs in again when publish answers insufficient permissions", async () => { + const calls: string[] = []; + let refused = false; + const client = new ZerozeroClient( + { username: "kapta", password: "zz-pass" }, + desk((pathname) => { + calls.push(pathname); + if (!refused && pathname === "/api/photo-sync/img-9") { + refused = true; + return Response.json({ error: "Insufficient permissions" }, { status: 403 }); + } + return Response.json({ synced: 1, failed: 0, failures: [] }); + }), + ); + await client.publish("12627743", "img-9"); + expect(calls).toEqual(["/api/photo-sync/img-9", "/api/photo-sync/img-9"]); }); it("publishes the whole game when the desk has no single-photo publish", async () => { @@ -133,6 +151,11 @@ describe("zerozero publish", () => { }), ); await client.publish("12627743", "img-9"); - expect(calls).toEqual(["/api/photo-sync/img-9", "/api/photo-sync/match/12627743"]); + expect(calls).toEqual([ + "/api/photo-sync/img-9", + "/api/photo-sync/img-9", + "/api/photo-sync/match/12627743", + "/api/photo-sync/match/12627743", + ]); }); }); diff --git a/apps/api/src/delivery/zerozero.ts b/apps/api/src/delivery/zerozero.ts index d3cc0de..169a84b 100644 --- a/apps/api/src/delivery/zerozero.ts +++ b/apps/api/src/delivery/zerozero.ts @@ -292,12 +292,29 @@ export class ZerozeroClient { private async postApi(path: string, timeoutMs: number, retry = true): Promise<{ status: number; body: unknown }> { await this.login(); - const { res } = await this.request(`${this.base}/api${path}`, { method: "POST" }, 10, timeoutMs); + // The desk's own client posts JSON. An empty object is what "send now" sends when it has no extra fields. + const { res } = await this.request( + `${this.base}/api${path}`, + { + method: "POST", + headers: { "content-type": "application/json", accept: "application/json" }, + body: "{}", + }, + 10, + timeoutMs, + ); + // 401: logged out. 403 "Insufficient permissions": the cookie is still sent, but the session is no longer + // the photographer. One fresh sign-in. The same refusal after that is the account, not a stale login. if (res.status === 401 && retry) { this.account = null; this.jar.clear(); return this.postApi(path, timeoutMs, false); } + if (res.status === 403 && retry) { + this.account = null; + this.jar.clear(); + return this.postApi(path, timeoutMs, false); + } const text = await res.text(); let body: unknown = null; if (text) { diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 8fbe32d..8be7480 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -477,8 +477,9 @@ The same queue also delivers to SFTP, FTP/FTPS and Dropbox (`delivery/transports author (`artist`: the photographer's name from the IPTC creator). The upload only reaches the photographer's desk. The public game shows the photo after publish: `POST /api/photo-sync/`, or `POST /api/photo-sync/match/` when the desk has no single-image publish (the same call as - "Sincronizar com zerozero"). A photographer account that is refused (403) still counts as delivered: the file - is on the desk, and that account cannot publish. Any other publish failure fails the delivery. The "folder" is the game: + "Sincronizar com zerozero"). A 403 signs in again once (a stale session uses that status, not 401). The same + refusal after the new login still counts as delivered: the file is on the desk. Any other publish failure fails + the delivery. The "folder" is the game: chosen for the event by pasting the game's link (kept in `events.zerozero_game_id`), or found among the desk's upcoming games by both teams and kick-off within 3 hours. The delivered item's remote path is `/` (`DELETE /api/images/` takes it back).