Don't call zerozero's delete API with the "synced-<file name>" 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/<id> gets a 400, not a 404, so the prior already-gone handling missed it.
This commit is contained in:
1 parent
4e99747ff6
commit
d204db4562
2 files changed
+10
No files matched your search
@@ -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<void> {
|
||||
// "synced-<file name>" (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;
|
||||
|
||||
@@ -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-<file name>' 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();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user