From f7a596610424966c3e0e0fce1a2b568a1353a9ad Mon Sep 17 00:00:00 2001 From: shuaiplus <2327005759@qq.com> Date: Mon, 23 Feb 2026 19:35:06 +0800 Subject: [PATCH] feat: add compatibility mode for deleting ciphers to support Bitwarden clients --- src/handlers/ciphers.ts | 23 +++++++++++++++++++++++ src/router.ts | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/handlers/ciphers.ts b/src/handlers/ciphers.ts index 98f4947..6abe6ac 100644 --- a/src/handlers/ciphers.ts +++ b/src/handlers/ciphers.ts @@ -204,6 +204,29 @@ export async function handleDeleteCipher(request: Request, env: Env, userId: str return jsonResponse(cipherToResponse(cipher)); } +// DELETE /api/ciphers/:id (compat mode) +// Bitwarden clients may call DELETE on a trashed item to purge it permanently. +// For compatibility: +// - If item is active -> soft delete. +// - If item is already soft-deleted -> hard delete. +export async function handleDeleteCipherCompat(request: Request, env: Env, userId: string, id: string): Promise { + const storage = new StorageService(env.DB); + const cipher = await storage.getCipher(id); + + if (!cipher || cipher.userId !== userId) { + return errorResponse('Cipher not found', 404); + } + + if (cipher.deletedAt) { + await deleteAllAttachmentsForCipher(env, id); + await storage.deleteCipher(id, userId); + await storage.updateRevisionDate(userId); + return new Response(null, { status: 204 }); + } + + return handleDeleteCipher(request, env, userId, id); +} + // DELETE /api/ciphers/:id (permanent) export async function handlePermanentDeleteCipher(request: Request, env: Env, userId: string, id: string): Promise { const storage = new StorageService(env.DB); diff --git a/src/router.ts b/src/router.ts index dc49840..c8226dc 100644 --- a/src/router.ts +++ b/src/router.ts @@ -17,6 +17,7 @@ import { handleCreateCipher, handleUpdateCipher, handleDeleteCipher, + handleDeleteCipherCompat, handlePermanentDeleteCipher, handleRestoreCipher, handlePartialUpdateCipher, @@ -419,7 +420,7 @@ export async function handleRequest(request: Request, env: Env): Promise