From 8065e088ebf4ee3fa6b86b37af67a1894fdd4c8e Mon Sep 17 00:00:00 2001 From: Alma Date: Sun, 13 Apr 2025 21:04:26 +0200 Subject: [PATCH] widget email 6 --- app/api/emails/route.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/api/emails/route.ts b/app/api/emails/route.ts index 897a7724..c34a2c18 100644 --- a/app/api/emails/route.ts +++ b/app/api/emails/route.ts @@ -19,12 +19,14 @@ export async function GET(req: NextRequest) { ); } - // First, try to get the user's Nextcloud ID using the Keycloak token + // First, try to get the user's Nextcloud ID using the OCS API const userInfoResponse = await fetch(`${nextcloudUrl}/ocs/v2.php/cloud/user`, { headers: { 'Authorization': `Bearer ${session.accessToken}`, 'Accept': 'application/json', 'OCS-APIRequest': 'true', + 'Content-Type': 'application/json', + 'X-Requested-With': 'XMLHttpRequest', }, }); @@ -32,7 +34,8 @@ export async function GET(req: NextRequest) { console.error('Failed to get user info:', { status: userInfoResponse.status, statusText: userInfoResponse.statusText, - url: userInfoResponse.url + url: userInfoResponse.url, + headers: Object.fromEntries(userInfoResponse.headers.entries()) }); if (userInfoResponse.status === 401) { @@ -56,12 +59,14 @@ export async function GET(req: NextRequest) { ); } - // Now try to access the Mail app - const response = await fetch(`${nextcloudUrl}/index.php/apps/mail/api/accounts`, { + // Now try to access the Mail app using OCS API + const response = await fetch(`${nextcloudUrl}/ocs/v2.php/apps/mail/api/v1/accounts`, { headers: { 'Authorization': `Bearer ${session.accessToken}`, 'Accept': 'application/json', + 'OCS-APIRequest': 'true', 'Content-Type': 'application/json', + 'X-Requested-With': 'XMLHttpRequest', }, }); @@ -69,7 +74,8 @@ export async function GET(req: NextRequest) { console.error('Mail app check failed:', { status: response.status, statusText: response.statusText, - url: response.url + url: response.url, + headers: Object.fromEntries(response.headers.entries()) }); if (response.status === 401) { @@ -82,7 +88,8 @@ export async function GET(req: NextRequest) { ); } - const accounts = await response.json(); + const data = await response.json(); + const accounts = data?.ocs?.data || []; // For now, return a success response with an empty array // We'll implement the actual message fetching once we confirm the correct endpoint