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