carnet api nc

This commit is contained in:
alma 2025-04-20 15:28:31 +02:00
parent 19daa51755
commit 7411a20f2a

View File

@ -53,7 +53,7 @@ async function parseXMLResponse(response: Response): Promise<any> {
async function createFolder(nextcloudUrl: string, username: string, password: string, folderPath: string) {
try {
// First check if folder exists
const checkResponse = await fetch(`${nextcloudUrl}/remote.php/dav/files/${encodeURIComponent(username)}/${encodeURIComponent(folderPath)}`, {
const checkResponse = await fetch(`${nextcloudUrl}/remote.php/dav/files/${encodeURIComponent(username)}/${folderPath}`, {
method: 'PROPFIND',
headers: {
'Authorization': `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`,
@ -67,7 +67,7 @@ async function createFolder(nextcloudUrl: string, username: string, password: st
}
// If folder doesn't exist, create it
const response = await fetch(`${nextcloudUrl}/remote.php/dav/files/${encodeURIComponent(username)}/${encodeURIComponent(folderPath)}`, {
const response = await fetch(`${nextcloudUrl}/remote.php/dav/files/${encodeURIComponent(username)}/${folderPath}`, {
method: 'MKCOL',
headers: {
'Authorization': `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`,
@ -79,7 +79,8 @@ async function createFolder(nextcloudUrl: string, username: string, password: st
console.error(`Failed to create folder ${folderPath}:`, {
status: response.status,
statusText: response.statusText,
error: errorText
error: errorText,
url: `${nextcloudUrl}/remote.php/dav/files/${encodeURIComponent(username)}/${folderPath}`
});
throw new Error(`Failed to create folder ${folderPath}: ${response.status} ${response.statusText}`);
}