widget email 13
This commit is contained in:
parent
a66a56f64d
commit
336426efae
@ -20,7 +20,7 @@ export async function GET(req: NextRequest) {
|
||||
}
|
||||
|
||||
// Try to access the Mail app using the Keycloak token
|
||||
const response = await fetch(`${nextcloudUrl}/ocs/v2.php/apps/mail/api/v1/accounts`, {
|
||||
const response = await fetch(`${nextcloudUrl}/ocs/v2.php/cloud/user`, {
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'OCS-APIRequest': 'true',
|
||||
@ -41,7 +41,7 @@ export async function GET(req: NextRequest) {
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
console.error('Mail app check failed:', {
|
||||
console.error('User info check failed:', {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
error: responseData,
|
||||
@ -58,7 +58,55 @@ export async function GET(req: NextRequest) {
|
||||
);
|
||||
}
|
||||
|
||||
const accounts = responseData?.ocs?.data || [];
|
||||
const userId = responseData?.ocs?.data?.id;
|
||||
if (!userId) {
|
||||
console.error('Failed to get user ID from Nextcloud');
|
||||
return NextResponse.json(
|
||||
{ error: "L'application Mail n'est pas disponible sur Nextcloud. Veuillez contacter votre administrateur." },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
// Now try to access the Mail app
|
||||
const mailResponse = await fetch(`${nextcloudUrl}/ocs/v2.php/apps/mail/api/v1/accounts`, {
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'OCS-APIRequest': 'true',
|
||||
'Content-Type': 'application/json',
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
'Authorization': `Bearer ${session.accessToken}`,
|
||||
},
|
||||
});
|
||||
|
||||
const mailResponseText = await mailResponse.text();
|
||||
let mailResponseData;
|
||||
|
||||
try {
|
||||
mailResponseData = JSON.parse(mailResponseText);
|
||||
} catch (error) {
|
||||
console.error('Failed to parse mail response:', mailResponseText);
|
||||
return NextResponse.json({ error: 'Invalid response format' }, { status: 500 });
|
||||
}
|
||||
|
||||
if (!mailResponse.ok) {
|
||||
console.error('Mail app check failed:', {
|
||||
status: mailResponse.status,
|
||||
statusText: mailResponse.statusText,
|
||||
error: mailResponseData,
|
||||
url: mailResponse.url,
|
||||
});
|
||||
|
||||
if (mailResponse.status === 401) {
|
||||
return NextResponse.json({ error: 'Nextcloud authentication failed' }, { status: 401 });
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: "L'application Mail n'est pas disponible sur Nextcloud. Veuillez contacter votre administrateur." },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
const accounts = mailResponseData?.ocs?.data || [];
|
||||
|
||||
// For now, return a success response with an empty array
|
||||
return NextResponse.json([]);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user