File
Blob: src/worker/webdav/mkcol.ts
| 1 | import { davError, emptyResponse } from "@/worker/dav/http"; |
| 2 | import type { SubjectRow } from "@/worker/db/d1/schema"; |
| 3 | import type { AppContext } from "@/worker/types"; |
| 4 | import { fileDavObject, resultError, type NormalizedFilesRequestPath } from "@/worker/webdav/object"; |
| 5 | import { parseContentLength, readFileDavWriteRequest } from "@/worker/webdav/request"; |
| 6 | |
| 7 | export async function handleMkcol(c: AppContext, subject: SubjectRow, path: NormalizedFilesRequestPath) { |
| 8 | const contentLength = parseContentLength(c.req.raw); |
| 9 | if (contentLength !== null && contentLength > 0) { |
| 10 | return davError(415, "MKCOL request bodies are not supported"); |
| 11 | } |
| 12 | if (contentLength === null && c.req.raw.body !== null && (await c.req.raw.arrayBuffer()).byteLength > 0) { |
| 13 | return davError(415, "MKCOL request bodies are not supported"); |
| 14 | } |
| 15 | const writeRequest = readFileDavWriteRequest(c.req.raw); |
| 16 | if (writeRequest instanceof Response) return writeRequest; |
| 17 | const result = await fileDavObject(c.env, subject.storageId).mkcol({ |
| 18 | subjectId: subject.id, |
| 19 | storageId: subject.storageId, |
| 20 | path: path.path, |
| 21 | ifHeader: writeRequest.ifHeader, |
| 22 | lockTokens: writeRequest.lockTokens, |
| 23 | nowMs: writeRequest.nowMs, |
| 24 | }); |
| 25 | return result.ok ? emptyResponse(201) : resultError(result); |
| 26 | } |