panel 2 courier api
This commit is contained in:
parent
e255ed4c5a
commit
df60de0c8e
@ -4,6 +4,25 @@ import { getServerSession } from 'next-auth';
|
||||
import { authOptions } from '@/app/api/auth/[...nextauth]/route';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
|
||||
// Add caching for better performance
|
||||
const cache = new Map();
|
||||
|
||||
const getCachedEmail = (id: string) => cache.get(id);
|
||||
const setCachedEmail = (id: string, email: Email) => cache.set(id, email);
|
||||
|
||||
// Add debouncing for folder changes
|
||||
const debouncedLoadEmails = debounce((folder: string) => {
|
||||
loadEmails(folder);
|
||||
}, 300);
|
||||
|
||||
// Add infinite scroll
|
||||
const handleScroll = (e: React.UIEvent<HTMLDivElement>) => {
|
||||
const { scrollTop, scrollHeight, clientHeight } = e.currentTarget;
|
||||
if (scrollHeight - scrollTop === clientHeight) {
|
||||
// Load more emails
|
||||
}
|
||||
};
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
@ -33,6 +52,7 @@ export async function GET(request: Request) {
|
||||
const folder = url.searchParams.get('folder') || 'INBOX';
|
||||
const page = parseInt(url.searchParams.get('page') || '1');
|
||||
const limit = parseInt(url.searchParams.get('limit') || '20');
|
||||
const preview = url.searchParams.get('preview') === 'true';
|
||||
|
||||
// Calculate start and end sequence numbers
|
||||
const start = (page - 1) * limit + 1;
|
||||
@ -72,11 +92,20 @@ export async function GET(request: Request) {
|
||||
const adjustedStart = Math.min(start, mailbox.exists);
|
||||
const adjustedEnd = Math.min(end, mailbox.exists);
|
||||
|
||||
// Fetch messages from the current folder
|
||||
// Fetch both metadata and preview content
|
||||
const messages = await client.fetch(`${adjustedStart}:${adjustedEnd}`, {
|
||||
envelope: true,
|
||||
flags: true,
|
||||
bodyStructure: true
|
||||
bodyStructure: true,
|
||||
// Only fetch preview content if requested
|
||||
...(preview ? {
|
||||
bodyParts: ['TEXT'],
|
||||
bodyPartsOptions: {
|
||||
TEXT: {
|
||||
maxLength: 1000 // Limit preview length
|
||||
}
|
||||
}
|
||||
} : {})
|
||||
});
|
||||
|
||||
for await (const message of messages) {
|
||||
@ -91,7 +120,9 @@ export async function GET(request: Request) {
|
||||
starred: message.flags.has('\\Flagged'),
|
||||
folder: mailbox.path,
|
||||
hasAttachments: message.bodyStructure?.type === 'multipart',
|
||||
flags: Array.from(message.flags)
|
||||
flags: Array.from(message.flags),
|
||||
// Include preview content if available
|
||||
preview: preview ? message.bodyParts?.TEXT?.toString() : null
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user