Skip to content
File

Blob: src/worker/webdav/mkcol.ts

typescript27 lines
1import { davError, emptyResponse } from "@/worker/dav/http";
2import type { SubjectRow } from "@/worker/db/d1/schema";
3import type { AppContext } from "@/worker/types";
4import { fileDavObject, resultError, type NormalizedFilesRequestPath } from "@/worker/webdav/object";
5import { parseContentLength, readFileDavWriteRequest } from "@/worker/webdav/request";
6 
7export 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}