import { deadPropInstructions, protectedProppatchMultistatus, proppatchMultistatus, readCollectionProppatch, } from "@/worker/dav/collection-handler"; import type { SubjectRow } from "@/worker/db/d1/schema"; import type { AppContext } from "@/worker/types"; import { fileDavObject, resultError, type NormalizedFilesRequestPath } from "@/worker/webdav/object"; import { readFileDavWriteRequest } from "@/worker/webdav/request"; export async function handleProppatch(c: AppContext, subject: SubjectRow, path: NormalizedFilesRequestPath) { const writeRequest = readFileDavWriteRequest(c.req.raw); if (writeRequest instanceof Response) return writeRequest; const proppatch = await readCollectionProppatch(c, "file-resource"); if (!proppatch.ok) return proppatch.response; const protectedResponse = protectedProppatchMultistatus(path.path.href, proppatch.value, "file-resource"); if (protectedResponse) return protectedResponse; const result = await fileDavObject(c.env, subject.storageId).proppatch({ subjectId: subject.id, storageId: subject.storageId, path: path.path, instructions: deadPropInstructions(proppatch.value), ...writeRequest, }); if (!result.ok) return resultError(result); return proppatchMultistatus(path.path.href, proppatch.value); }