carnet api nc
This commit is contained in:
parent
fb59a0e160
commit
1acecd3678
@ -82,11 +82,15 @@ async function getWebDAVCredentials(nextcloudUrl: string, username: string, admi
|
|||||||
throw new Error(`Failed to set password: ${setPasswordResponse.status} ${setPasswordResponse.statusText}`);
|
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)}/`, {
|
const verifyResponse = await fetch(`${nextcloudUrl}/remote.php/dav/files/${encodeURIComponent(username)}/`, {
|
||||||
|
method: 'PROPFIND',
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Basic ${Buffer.from(`${username}:${newPassword}`).toString('base64')}`,
|
'Authorization': `Basic ${Buffer.from(`${username}:${newPassword}`).toString('base64')}`,
|
||||||
|
'Depth': '1',
|
||||||
|
'Content-Type': 'application/xml',
|
||||||
},
|
},
|
||||||
|
body: '<?xml version="1.0" encoding="UTF-8"?><d:propfind xmlns:d="DAV:"><d:prop><d:resourcetype/></d:prop></d:propfind>',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!verifyResponse.ok) {
|
if (!verifyResponse.ok) {
|
||||||
@ -156,11 +160,13 @@ export async function GET() {
|
|||||||
console.log('Requesting WebDAV URL:', webdavUrl);
|
console.log('Requesting WebDAV URL:', webdavUrl);
|
||||||
|
|
||||||
const foldersResponse = await fetch(webdavUrl, {
|
const foldersResponse = await fetch(webdavUrl, {
|
||||||
|
method: 'PROPFIND',
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Basic ${Buffer.from(`${nextcloudUsername}:${webdavPassword}`).toString('base64')}`,
|
'Authorization': `Basic ${Buffer.from(`${nextcloudUsername}:${webdavPassword}`).toString('base64')}`,
|
||||||
'Depth': '1',
|
'Depth': '1',
|
||||||
'Content-Type': 'application/xml',
|
'Content-Type': 'application/xml',
|
||||||
},
|
},
|
||||||
|
body: '<?xml version="1.0" encoding="UTF-8"?><d:propfind xmlns:d="DAV:"><d:prop><d:resourcetype/><d:displayname/></d:prop></d:propfind>',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (foldersResponse.status === 429) {
|
if (foldersResponse.status === 429) {
|
||||||
@ -192,9 +198,13 @@ export async function GET() {
|
|||||||
const isCollection = resourceType?.getElementsByTagName('d:collection').length > 0;
|
const isCollection = resourceType?.getElementsByTagName('d:collection').length > 0;
|
||||||
|
|
||||||
if (isCollection) {
|
if (isCollection) {
|
||||||
const displayName = response.getElementsByTagName('d:displayname')[0]?.textContent;
|
const href = response.getElementsByTagName('d:href')[0]?.textContent;
|
||||||
if (displayName && displayName !== nextcloudUsername) {
|
if (href) {
|
||||||
folders.push(displayName);
|
// Extract folder name from href
|
||||||
|
const folderName = decodeURIComponent(href.split('/').filter(Boolean).pop() || '');
|
||||||
|
if (folderName && folderName !== nextcloudUsername) {
|
||||||
|
folders.push(folderName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user