Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AmyPfuNc4sCRfaF3oURXZz
37 lines
2.1 KiB
TypeScript
37 lines
2.1 KiB
TypeScript
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 };
|
|
}
|