Skip to content
File

Blob: src/worker/webdav/delete.ts

typescript25 lines
1import { emptyResponse } from "@/worker/dav/http";
2import { maxDavDepthInfinityNodes } from "@/worker/dav/limits";
3import type { SubjectRow } from "@/worker/db/d1/schema";
4import type { AppContext } from "@/worker/types";
5import { enqueueGc } from "@/worker/webdav/gc";
6import { fileDavObject, resultError, type NormalizedFilesRequestPath } from "@/worker/webdav/object";
7import { readFileDavWriteRequest, validateDeleteDepth } from "@/worker/webdav/request";
8 
9export 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}