import { retryUntilReady, type BlobGcMessage } from "@/worker/queues/blob-gc"; import type { QueueHandleResult } from "@/worker/queues/types"; import { deleteFileBlob } from "@/worker/r2/blobs"; export async function enqueueBlobGc(env: Env, messages: BlobGcMessage[]): Promise { if (messages.length === 0) return; await env.BLOB_GC.sendBatch(messages.map((body) => ({ body }))); } export async function handleBlobGc(env: Env, message: BlobGcMessage, nowMs = Date.now()): Promise { const pendingRetry = retryUntilReady(message, nowMs); if (pendingRetry) return pendingRetry; const object = env.FILE_DAV.getByName(message.storage_id); const result = await object.verifyBlobUnreferenced({ subjectId: message.subject_id, blobId: message.blob_id, blobKey: message.blob_key, nowMs, }); if (result.unreferenced) await deleteFileBlob(env.FILE_BLOBS, message.blob_key); return { action: "ack" }; }