Projektordner in der Nextcloud anlegen und je nach Status verschieben (P10)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmyPfuNc4sCRfaF3oURXZz
This commit is contained in:
Claude
2026-10-19 19:07:03 +00:00
parent 6615acf936
commit a3bb310cea
9 changed files with 256 additions and 4 deletions

36
test/falsche-nextcloud.ts Normal file
View File

@@ -0,0 +1,36 @@
import { Nextcloud } from "../src/server/nextcloud.js";
/** Kleine WebDAV-Nachbildung im Speicher: nur Ordner, wie Nextcloud sie beantwortet */
export function falscheNextcloud(basis = "https://cloud.test/remote.php/dav/files/henning/Projekte") {
const ordner = new Set<string>();
const pfad = (u: string) => decodeURIComponent(new URL(u).pathname).replace(/\/+$/, "");
const wurzel = pfad(basis);
ordner.add(wurzel);
const abruf = (async (u: string | URL, init?: RequestInit) => {
const p = pfad(String(u));
const kopf = (init?.headers ?? {}) as Record<string, string>;
const eltern = p.slice(0, p.lastIndexOf("/"));
switch (init?.method) {
case "PROPFIND": {
if (!ordner.has(p)) return new Response(null, { status: 404 });
const kinder = kopf.depth === "1" ? [...ordner].filter((o) => o.startsWith(p + "/") && !o.slice(p.length + 1).includes("/")) : [];
const hrefs = [p, ...kinder].map((o) => `<d:response><d:href>${o.split("/").map(encodeURIComponent).join("/")}/</d:href></d:response>`).join("");
return new Response(`<?xml version="1.0"?><d:multistatus xmlns:d="DAV:">${hrefs}</d:multistatus>`, { status: 207 });
}
case "MKCOL":
if (ordner.has(p)) return new Response(null, { status: 405 });
if (!ordner.has(eltern)) return new Response(null, { status: 409 });
ordner.add(p);
return new Response(null, { status: 201 });
case "MOVE": {
const ziel = pfad(kopf.destination!);
if (!ordner.has(p) || ordner.has(ziel) || !ordner.has(ziel.slice(0, ziel.lastIndexOf("/")))) return new Response(null, { status: 409 });
for (const o of [...ordner]) if (o === p || o.startsWith(p + "/")) { ordner.delete(o); ordner.add(ziel + o.slice(p.length)); }
return new Response(null, { status: 201 });
}
}
return new Response(null, { status: 400 });
}) as typeof fetch;
const relativ = () => [...ordner].filter((o) => o !== wurzel).map((o) => o.slice(wurzel.length + 1)).sort();
return { nc: new Nextcloud({ url: basis, benutzer: "henning", passwort: "geheim" }, abruf), ordner, wurzel, relativ };
}