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(); 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; 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) => `${o.split("/").map(encodeURIComponent).join("/")}/`).join(""); return new Response(`${hrefs}`, { 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 }; }