carnet api nc
This commit is contained in:
parent
9b039cb6fd
commit
dbd5157dde
@ -118,7 +118,7 @@ export async function GET() {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
|
||||
if (!session?.user?.email || !session?.accessToken) {
|
||||
if (!session?.user?.email || !session?.user?.id || !session?.accessToken) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Unauthorized' },
|
||||
{ status: 401 }
|
||||
@ -148,10 +148,14 @@ export async function GET() {
|
||||
}
|
||||
|
||||
try {
|
||||
// Use the Keycloak ID as the Nextcloud username
|
||||
const nextcloudUsername = `cube-${session.user.id}`;
|
||||
console.log('Using Nextcloud username:', nextcloudUsername);
|
||||
|
||||
// Get or create WebDAV credentials
|
||||
const webdavPassword = await getWebDAVCredentials(
|
||||
nextcloudUrl,
|
||||
session.user.email,
|
||||
nextcloudUsername,
|
||||
adminUsername,
|
||||
adminPassword
|
||||
);
|
||||
@ -161,12 +165,12 @@ export async function GET() {
|
||||
}
|
||||
|
||||
// Get user's folders using WebDAV with Basic authentication
|
||||
const webdavUrl = `${nextcloudUrl}/remote.php/dav/files/${encodeURIComponent(session.user.email)}/`;
|
||||
const webdavUrl = `${nextcloudUrl}/remote.php/dav/files/${encodeURIComponent(nextcloudUsername)}/`;
|
||||
console.log('Requesting WebDAV URL:', webdavUrl);
|
||||
|
||||
const foldersResponse = await fetch(webdavUrl, {
|
||||
headers: {
|
||||
'Authorization': `Basic ${Buffer.from(`${session.user.email}:${webdavPassword}`).toString('base64')}`,
|
||||
'Authorization': `Basic ${Buffer.from(`${nextcloudUsername}:${webdavPassword}`).toString('base64')}`,
|
||||
'Depth': '1',
|
||||
'Content-Type': 'application/xml',
|
||||
},
|
||||
@ -202,7 +206,7 @@ export async function GET() {
|
||||
|
||||
if (isCollection) {
|
||||
const displayName = response.getElementsByTagName('d:displayname')[0]?.textContent;
|
||||
if (displayName && displayName !== session.user.email) {
|
||||
if (displayName && displayName !== nextcloudUsername) {
|
||||
folders.push(displayName);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user