feat: add compatibility mode for deleting ciphers to support Bitwarden clients

This commit is contained in:
shuaiplus
2026-02-23 19:35:06 +08:00
parent 747cad35f5
commit f7a5966104
2 changed files with 25 additions and 1 deletions
+23
View File
@@ -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<Response> {
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<Response> {
const storage = new StorageService(env.DB);