Restic-Kompatibilität, POST, rekursives MKCOL, findstr /C: Fix
- Server: POST für Uploads, rekursives MKCOL/PUT, ensureFolderExists - PUT: fehlende Elternordner werden erstellt - Scripts: findstr /C: für Literalsuche (Punkt-Konflikt behoben) - Docs: Restic + rclone Hinweis Made-with: Cursor
This commit is contained in:
@@ -67,8 +67,8 @@ function basicAuth(req, res, next) {
|
||||
|
||||
app.use(basicAuth);
|
||||
|
||||
// Request-Body: PUT als Raw (Datei-Upload), PROPFIND als Text
|
||||
app.use(express.raw({ type: (req) => req.method === 'PUT', limit: '1gb' }));
|
||||
// Request-Body: PUT/POST als Raw (Datei-Upload), PROPFIND als Text
|
||||
app.use(express.raw({ type: (req) => req.method === 'PUT' || req.method === 'POST', limit: '1gb' }));
|
||||
app.use(express.text({ type: 'application/xml', limit: '1kb' }));
|
||||
|
||||
/**
|
||||
@@ -254,7 +254,37 @@ async function getContext() {
|
||||
}
|
||||
|
||||
/**
|
||||
* MKCOL Handler – Ordner anlegen
|
||||
* Stellt sicher, dass ein Ordnerpfad existiert (erstellt fehlende Eltern rekursiv).
|
||||
* @returns {Promise<{ uuid: string } | null>} Ordner oder null
|
||||
*/
|
||||
async function ensureFolderExists(storage, rootUuid, path) {
|
||||
const segments = pathToSegments(path);
|
||||
let currentUuid = rootUuid;
|
||||
|
||||
for (const segment of segments) {
|
||||
const [contentPromise] = storage.getFolderContentByUuid({ folderUuid: currentUuid });
|
||||
const content = await contentPromise;
|
||||
const child = content?.children?.find((c) => {
|
||||
const name = getPlainName(c.name, c.plain_name ?? c.plainName, c.parent_id ?? c.parentId, null);
|
||||
return sanitizeForPath(name).toLowerCase() === sanitizeForPath(segment).toLowerCase();
|
||||
});
|
||||
if (child) {
|
||||
currentUuid = child.uuid;
|
||||
} else {
|
||||
const [createPromise] = storage.createFolderByUuid({
|
||||
parentFolderUuid: currentUuid,
|
||||
plainName: segment,
|
||||
});
|
||||
const created = await createPromise;
|
||||
currentUuid = created?.uuid;
|
||||
if (!currentUuid) return null;
|
||||
}
|
||||
}
|
||||
return { uuid: currentUuid };
|
||||
}
|
||||
|
||||
/**
|
||||
* MKCOL Handler – Ordner anlegen (rekursiv: fehlende Eltern werden erstellt)
|
||||
*/
|
||||
async function handleMkcol(req, res) {
|
||||
let path = req.url || '/';
|
||||
@@ -279,7 +309,10 @@ async function handleMkcol(req, res) {
|
||||
|
||||
try {
|
||||
const { storage, rootUuid } = await getContext();
|
||||
const parent = await resolveFolder(storage, rootUuid, parentPath);
|
||||
const parent =
|
||||
parentPath && parentPath !== '/'
|
||||
? await ensureFolderExists(storage, rootUuid, parentPath)
|
||||
: { uuid: rootUuid };
|
||||
if (!parent) {
|
||||
res.status(409).send('Übergeordneter Ordner existiert nicht');
|
||||
return;
|
||||
@@ -582,7 +615,10 @@ async function handlePut(req, res) {
|
||||
const parentPath = segmentsToPath(segments.slice(0, -1));
|
||||
const fileName = segments[segments.length - 1];
|
||||
|
||||
const parent = await resolveFolder(storage, rootUuid, parentPath);
|
||||
let parent = await resolveFolder(storage, rootUuid, parentPath);
|
||||
if (!parent && parentPath && parentPath !== '/') {
|
||||
parent = await ensureFolderExists(storage, rootUuid, parentPath);
|
||||
}
|
||||
if (!parent) {
|
||||
res.status(409).send('Zielordner existiert nicht');
|
||||
return;
|
||||
@@ -664,7 +700,7 @@ async function handlePut(req, res) {
|
||||
|
||||
res.status(201).send();
|
||||
} catch (err) {
|
||||
console.error('PUT Fehler:', err.message);
|
||||
console.error('PUT Fehler:', path, err.message);
|
||||
if (err.message?.includes('Token') || err.response?.status === 401) {
|
||||
res.status(401).send('Nicht autorisiert – Token erneuern: https://drive.internxt.com');
|
||||
return;
|
||||
@@ -676,7 +712,7 @@ async function handlePut(req, res) {
|
||||
// WebDAV Endpoints
|
||||
app.options('*', (req, res) => {
|
||||
res.set('DAV', '1, 2');
|
||||
res.set('Allow', 'OPTIONS, PROPFIND, GET, HEAD, PUT, DELETE, MKCOL, MOVE');
|
||||
res.set('Allow', 'OPTIONS, PROPFIND, GET, HEAD, PUT, POST, DELETE, MKCOL, MOVE');
|
||||
res.sendStatus(200);
|
||||
});
|
||||
|
||||
@@ -700,7 +736,7 @@ app.use((req, res, next) => {
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (req.method === 'PUT') {
|
||||
if (req.method === 'PUT' || req.method === 'POST') {
|
||||
handlePut(req, res).catch((err) => {
|
||||
console.error('PUT unhandled:', err);
|
||||
if (!res.headersSent) res.status(500).send(err.message);
|
||||
|
||||
Reference in New Issue
Block a user