From 1acecd36783e04facd3d499247893bff77d8b56f Mon Sep 17 00:00:00 2001 From: alma Date: Sun, 20 Apr 2025 14:41:20 +0200 Subject: [PATCH] carnet api nc --- app/api/nextcloud/status/route.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/api/nextcloud/status/route.ts b/app/api/nextcloud/status/route.ts index 492b1588..ed01c0b0 100644 --- a/app/api/nextcloud/status/route.ts +++ b/app/api/nextcloud/status/route.ts @@ -82,11 +82,15 @@ async function getWebDAVCredentials(nextcloudUrl: string, username: string, admi throw new Error(`Failed to set password: ${setPasswordResponse.status} ${setPasswordResponse.statusText}`); } - // Verify the password was set by trying to authenticate + // Verify the password was set by trying to authenticate with PROPFIND const verifyResponse = await fetch(`${nextcloudUrl}/remote.php/dav/files/${encodeURIComponent(username)}/`, { + method: 'PROPFIND', headers: { 'Authorization': `Basic ${Buffer.from(`${username}:${newPassword}`).toString('base64')}`, + 'Depth': '1', + 'Content-Type': 'application/xml', }, + body: '', }); if (!verifyResponse.ok) { @@ -156,11 +160,13 @@ export async function GET() { console.log('Requesting WebDAV URL:', webdavUrl); const foldersResponse = await fetch(webdavUrl, { + method: 'PROPFIND', headers: { 'Authorization': `Basic ${Buffer.from(`${nextcloudUsername}:${webdavPassword}`).toString('base64')}`, 'Depth': '1', 'Content-Type': 'application/xml', }, + body: '', }); if (foldersResponse.status === 429) { @@ -192,9 +198,13 @@ export async function GET() { const isCollection = resourceType?.getElementsByTagName('d:collection').length > 0; if (isCollection) { - const displayName = response.getElementsByTagName('d:displayname')[0]?.textContent; - if (displayName && displayName !== nextcloudUsername) { - folders.push(displayName); + const href = response.getElementsByTagName('d:href')[0]?.textContent; + if (href) { + // Extract folder name from href + const folderName = decodeURIComponent(href.split('/').filter(Boolean).pop() || ''); + if (folderName && folderName !== nextcloudUsername) { + folders.push(folderName); + } } } }