courrier multi account restore compose
This commit is contained in:
parent
202a0e07d8
commit
8cf5a72f41
@ -14,7 +14,7 @@ import { getCachedEmailContent, invalidateEmailContentCache } from '@/lib/redis'
|
|||||||
|
|
||||||
export async function GET(
|
export async function GET(
|
||||||
request: Request,
|
request: Request,
|
||||||
{ params }: { params: { id: string } }
|
context: { params: { id: string } }
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
@ -25,7 +25,9 @@ export async function GET(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { id } = params;
|
// Await params as per Next.js requirements
|
||||||
|
const { params } = context;
|
||||||
|
const id = params?.id;
|
||||||
if (!id) {
|
if (!id) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: "Missing email ID" },
|
{ error: "Missing email ID" },
|
||||||
@ -39,7 +41,7 @@ export async function GET(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Try to get email from Redis cache first
|
// Try to get email from Redis cache first
|
||||||
const cachedEmail = await getCachedEmailContent(session.user.id, id);
|
const cachedEmail = await getCachedEmailContent(session.user.id, accountId || 'default', id);
|
||||||
if (cachedEmail) {
|
if (cachedEmail) {
|
||||||
console.log(`Using cached email content for ${session.user.id}:${id}`);
|
console.log(`Using cached email content for ${session.user.id}:${id}`);
|
||||||
return NextResponse.json(cachedEmail);
|
return NextResponse.json(cachedEmail);
|
||||||
@ -48,7 +50,7 @@ export async function GET(
|
|||||||
console.log(`Cache miss for email content ${session.user.id}:${id}, fetching from IMAP`);
|
console.log(`Cache miss for email content ${session.user.id}:${id}, fetching from IMAP`);
|
||||||
|
|
||||||
// Use the email service to fetch the email content
|
// Use the email service to fetch the email content
|
||||||
const email = await getEmailContent(session.user.id, id, folder, accountId);
|
const email = await getEmailContent(session.user.id, id, folder, accountId || undefined);
|
||||||
|
|
||||||
// Return the complete email object
|
// Return the complete email object
|
||||||
return NextResponse.json(email);
|
return NextResponse.json(email);
|
||||||
@ -71,7 +73,7 @@ export async function GET(
|
|||||||
// Add a route to mark email as read
|
// Add a route to mark email as read
|
||||||
export async function POST(
|
export async function POST(
|
||||||
request: Request,
|
request: Request,
|
||||||
{ params }: { params: { id: string } }
|
context: { params: { id: string } }
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
@ -82,7 +84,9 @@ export async function POST(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { id } = params;
|
// Await params as per Next.js requirements
|
||||||
|
const { params } = context;
|
||||||
|
const id = params?.id;
|
||||||
if (!id) {
|
if (!id) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: "Missing email ID" },
|
{ error: "Missing email ID" },
|
||||||
@ -101,6 +105,7 @@ export async function POST(
|
|||||||
|
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const folder = searchParams.get("folder") || "INBOX";
|
const folder = searchParams.get("folder") || "INBOX";
|
||||||
|
const accountId = searchParams.get("accountId");
|
||||||
|
|
||||||
// Use the email service to mark the email
|
// Use the email service to mark the email
|
||||||
const success = await markEmailReadStatus(
|
const success = await markEmailReadStatus(
|
||||||
@ -118,7 +123,7 @@ export async function POST(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Invalidate cache for this email
|
// Invalidate cache for this email
|
||||||
await invalidateEmailContentCache(session.user.id, id);
|
await invalidateEmailContentCache(session.user.id, accountId || 'default', id);
|
||||||
|
|
||||||
return NextResponse.json({ success: true });
|
return NextResponse.json({ success: true });
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user