carnet api nc
This commit is contained in:
parent
19daa51755
commit
7411a20f2a
@ -53,7 +53,7 @@ async function parseXMLResponse(response: Response): Promise<any> {
|
|||||||
async function createFolder(nextcloudUrl: string, username: string, password: string, folderPath: string) {
|
async function createFolder(nextcloudUrl: string, username: string, password: string, folderPath: string) {
|
||||||
try {
|
try {
|
||||||
// First check if folder exists
|
// 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',
|
method: 'PROPFIND',
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`,
|
'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
|
// 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',
|
method: 'MKCOL',
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`,
|
'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}:`, {
|
console.error(`Failed to create folder ${folderPath}:`, {
|
||||||
status: response.status,
|
status: response.status,
|
||||||
statusText: response.statusText,
|
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}`);
|
throw new Error(`Failed to create folder ${folderPath}: ${response.status} ${response.statusText}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user