File
Blob: src/worker/webdav/proppatch.ts
| 1 | import { |
| 2 | deadPropInstructions, |
| 3 | protectedProppatchMultistatus, |
| 4 | proppatchMultistatus, |
| 5 | readCollectionProppatch, |
| 6 | } from "@/worker/dav/collection-handler"; |
| 7 | import type { SubjectRow } from "@/worker/db/d1/schema"; |
| 8 | import type { AppContext } from "@/worker/types"; |
| 9 | import { fileDavObject, resultError, type NormalizedFilesRequestPath } from "@/worker/webdav/object"; |
| 10 | import { readFileDavWriteRequest } from "@/worker/webdav/request"; |
| 11 | |
| 12 | export async function handleProppatch(c: AppContext, subject: SubjectRow, path: NormalizedFilesRequestPath) { |
| 13 | const writeRequest = readFileDavWriteRequest(c.req.raw); |
| 14 | if (writeRequest instanceof Response) return writeRequest; |
| 15 | const proppatch = await readCollectionProppatch(c, "file-resource"); |
| 16 | if (!proppatch.ok) return proppatch.response; |
| 17 | |
| 18 | const protectedResponse = protectedProppatchMultistatus(path.path.href, proppatch.value, "file-resource"); |
| 19 | if (protectedResponse) return protectedResponse; |
| 20 | |
| 21 | const result = await fileDavObject(c.env, subject.storageId).proppatch({ |
| 22 | subjectId: subject.id, |
| 23 | storageId: subject.storageId, |
| 24 | path: path.path, |
| 25 | instructions: deadPropInstructions(proppatch.value), |
| 26 | ...writeRequest, |
| 27 | }); |
| 28 | if (!result.ok) return resultError(result); |
| 29 | return proppatchMultistatus(path.path.href, proppatch.value); |
| 30 | } |