From d204db45627482de86c673e2f218c86f4c2f03e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Alves?= Date: Tue, 20 Oct 2026 11:09:43 +0100 Subject: [PATCH] Don't call zerozero's delete API with the "synced-" placeholder id Upload returns that sentinel when the desk already had the file (no real image id ever existed for it); passing it to DELETE /api/images/ gets a 400, not a 404, so the prior already-gone handling missed it. --- apps/api/src/delivery/zerozero.ts | 3 +++ apps/api/test/zerozero-remove.test.ts | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/apps/api/src/delivery/zerozero.ts b/apps/api/src/delivery/zerozero.ts index d9c5686..593cd3f 100644 --- a/apps/api/src/delivery/zerozero.ts +++ b/apps/api/src/delivery/zerozero.ts @@ -265,6 +265,9 @@ export class ZerozeroClient { /** Takes an uploaded image back. Already gone (or no longer this account's to remove) is not an error. */ async remove(imageId: string): Promise { + // "synced-" (from `upload`, when the desk already had the file) is not a real image id: there was + // never anything of ours to take back, and the desk answers a bare DELETE on it with 400, not 404. + if (!/^\d+$/.test(imageId)) return; await this.json(`/images/${encodeURIComponent(imageId)}`, { method: "DELETE" }).catch((err: unknown) => { if (err instanceof TransportError && /: (403|404)$/.test(err.message)) return; throw err; diff --git a/apps/api/test/zerozero-remove.test.ts b/apps/api/test/zerozero-remove.test.ts index 43ae706..8ee324c 100644 --- a/apps/api/test/zerozero-remove.test.ts +++ b/apps/api/test/zerozero-remove.test.ts @@ -39,4 +39,11 @@ describe("ZerozeroClient.remove", () => { expect(err).toBeInstanceOf(TransportError); expect((err as TransportError).transient).toBe(true); }); + + it("skips the call for a 'synced-' placeholder id: there was never a real image to take back", async () => { + const client = new ZerozeroClient({ username: "foto", password: "segredo" }, (() => { + throw new Error("should not call fetch"); + }) as unknown as typeof fetch); + await expect(client.remove("synced-PSR11532.jpg")).resolves.toBeUndefined(); + }); });