carnet api nc

This commit is contained in:
alma 2025-04-20 15:21:41 +02:00
parent 97eb7f08f4
commit b40fbc6c98

View File

@ -63,6 +63,22 @@ async function createFolder(nextcloudUrl: string, username: string, password: st
}
}
async function ensureFolderStructure(nextcloudUrl: string, username: string, password: string) {
try {
// Create Private folder if it doesn't exist
await createFolder(nextcloudUrl, username, password, 'Private');
// Create Diary folder if it doesn't exist
await createFolder(nextcloudUrl, username, password, 'Private/Diary');
// Create Health folder if it doesn't exist
await createFolder(nextcloudUrl, username, password, 'Private/Health');
} catch (error) {
console.error('Error creating folder structure:', error);
throw error;
}
}
async function getWebDAVCredentials(nextcloudUrl: string, username: string, adminUsername: string, adminPassword: string, userId: string) {
try {
// Check if credentials exist in database
@ -83,6 +99,8 @@ async function getWebDAVCredentials(nextcloudUrl: string, username: string, admi
});
if (verifyResponse.ok) {
// Ensure required folders exist
await ensureFolderStructure(nextcloudUrl, username, credentials.password);
return credentials.password;
}
@ -136,9 +154,7 @@ async function getWebDAVCredentials(nextcloudUrl: string, username: string, admi
});
// Create required folder structure
await createFolder(nextcloudUrl, username, newPassword, 'Private');
await createFolder(nextcloudUrl, username, newPassword, 'Private/Diary');
await createFolder(nextcloudUrl, username, newPassword, 'Private/Health');
await ensureFolderStructure(nextcloudUrl, username, newPassword);
return newPassword;
} catch (error) {