File
Blob: src/worker/webdav/delete.ts
| 1 | import { emptyResponse } from "@/worker/dav/http"; |
| 2 | import { maxDavDepthInfinityNodes } from "@/worker/dav/limits"; |
| 3 | import type { SubjectRow } from "@/worker/db/d1/schema"; |
| 4 | import type { AppContext } from "@/worker/types"; |
| 5 | import { enqueueGc } from "@/worker/webdav/gc"; |
| 6 | import { fileDavObject, resultError, type NormalizedFilesRequestPath } from "@/worker/webdav/object"; |
| 7 | import { readFileDavWriteRequest, validateDeleteDepth } from "@/worker/webdav/request"; |
| 8 | |
| 9 | export async function handleDelete(c: AppContext, subject: SubjectRow, path: NormalizedFilesRequestPath) { |
| 10 | const depthError = validateDeleteDepth(c.req.header("depth") ?? null); |
| 11 | if (depthError) return depthError; |
| 12 | const writeRequest = readFileDavWriteRequest(c.req.raw); |
| 13 | if (writeRequest instanceof Response) return writeRequest; |
| 14 | const result = await fileDavObject(c.env, subject.storageId).delete({ |
| 15 | subjectId: subject.id, |
| 16 | storageId: subject.storageId, |
| 17 | path: path.path, |
| 18 | ...writeRequest, |
| 19 | maxNodes: maxDavDepthInfinityNodes(c.env), |
| 20 | }); |
| 21 | if (!result.ok) return resultError(result); |
| 22 | await enqueueGc(c, subject, result.blobGc); |
| 23 | return emptyResponse(204); |
| 24 | } |