first version
This commit is contained in:
30
app/api/resend-domain/route.ts
Normal file
30
app/api/resend-domain/route.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { db } from '@/app/db/drizzle';
|
||||
import { domains, emails } from '@/app/db/schema';
|
||||
import { authenticate } from '@/app/lib/utils';
|
||||
import { eq } from 'drizzle-orm';
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
if (!authenticate(req)) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
|
||||
const { bucket } = await req.json();
|
||||
if (!bucket) return NextResponse.json({ error: 'Missing bucket' }, { status: 400 });
|
||||
|
||||
const [domain] = await db.select().from(domains).where(eq(domains.bucket, bucket));
|
||||
if (!domain) return NextResponse.json({ error: 'Domain not found' }, { status: 404 });
|
||||
|
||||
const unprocessed = await db.select({ s3Key: emails.s3Key }).from(emails).where(eq(emails.processed, false));
|
||||
|
||||
let count = 0;
|
||||
for (const em of unprocessed) {
|
||||
// Call POST /api/email internally for resend (updates DB/S3)
|
||||
await fetch(`${req.headers.get('origin')}/api/email`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', Authorization: req.headers.get('Authorization')! },
|
||||
body: JSON.stringify({ bucket, key: em.s3Key }),
|
||||
});
|
||||
count++;
|
||||
}
|
||||
|
||||
return NextResponse.json({ message: `Resent ${count} emails` });
|
||||
}
|
||||
Reference in New Issue
Block a user