30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { db } from '@/app/db/drizzle';
|
|
import { emails } from '@/app/db/schema';
|
|
import { authenticate } from '@/app/lib/utils';
|
|
import { eq } from 'drizzle-orm';
|
|
|
|
export async function GET(req: NextRequest) {
|
|
if (!authenticate(req)) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
|
|
const { searchParams } = new URL(req.url);
|
|
const bucket = searchParams.get('bucket');
|
|
const key = searchParams.get('key');
|
|
if (!bucket || !key) return NextResponse.json({ error: 'Missing params' }, { status: 400 });
|
|
|
|
const [email] = await db.select().from(emails).where(eq(emails.s3Key, key));
|
|
if (!email) return NextResponse.json({ error: 'Email not found' }, { status: 404 });
|
|
|
|
return NextResponse.json({
|
|
subject: email.subject,
|
|
from: email.from,
|
|
to: email.to?.join(', '),
|
|
html: email.html,
|
|
raw: email.raw,
|
|
processed: email.processed ? 'true' : 'false',
|
|
processedAt: email.processedAt?.toISOString() || null,
|
|
processedBy: email.processedBy,
|
|
queuedTo: email.queuedTo,
|
|
status: email.status,
|
|
});
|
|
} |