panel 2 courier api restore
This commit is contained in:
parent
8a4a18c1c7
commit
6d319af061
@ -159,9 +159,13 @@ export async function GET(request: Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log('Fetching messages with options:', fetchOptions);
|
console.log('Fetching messages with options:', fetchOptions);
|
||||||
const messages = await client.fetch(`${adjustedStart}:${adjustedEnd}`, fetchOptions);
|
const fetchPromises = [];
|
||||||
|
for (let i = adjustedStart; i <= adjustedEnd; i++) {
|
||||||
|
fetchPromises.push(client.fetchOne(i, fetchOptions));
|
||||||
|
}
|
||||||
|
const results = await Promise.all(fetchPromises);
|
||||||
|
|
||||||
for await (const message of messages) {
|
for await (const message of results) {
|
||||||
console.log('Processing message ID:', message.uid);
|
console.log('Processing message ID:', message.uid);
|
||||||
const emailData: any = {
|
const emailData: any = {
|
||||||
id: message.uid,
|
id: message.uid,
|
||||||
@ -209,12 +213,17 @@ export async function GET(request: Request) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return NextResponse.json(responseData);
|
return NextResponse.json(responseData);
|
||||||
} finally {
|
} catch (error) {
|
||||||
try {
|
if (error.source === 'timeout') {
|
||||||
await client.logout();
|
// Retry with exponential backoff
|
||||||
console.log('IMAP client logged out');
|
return retryOperation(operation, attempt + 1);
|
||||||
} catch (e) {
|
} else if (error.source === 'auth') {
|
||||||
console.error('Error during logout:', e);
|
// Prompt for credentials refresh
|
||||||
|
return NextResponse.json({ error: 'Authentication failed', code: 'AUTH_ERROR' });
|
||||||
|
} else {
|
||||||
|
// General error handling
|
||||||
|
console.error('Operation failed:', error);
|
||||||
|
return NextResponse.json({ error: 'Operation failed', details: error.message });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -224,4 +233,15 @@ export async function GET(request: Request) {
|
|||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||||
|
// Mark as read logic...
|
||||||
|
|
||||||
|
// Invalidate cache entries for this folder
|
||||||
|
Object.keys(emailListCache).forEach(key => {
|
||||||
|
if (key.includes(`${userId}:${folderName}`)) {
|
||||||
|
delete emailListCache[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user