Files
lead-scraper/app/api/export/[jobId]/route.ts
Timo Uttenweiler facf8c9f69 Initial commit: LeadFlow lead generation platform
Full-stack Next.js 16 app with three scraping pipelines:
- AirScale CSV → Anymailfinder Bulk Decision Maker search
- LinkedIn Sales Navigator → Vayne → Anymailfinder email enrichment
- Apify Google SERP → domain extraction → Anymailfinder bulk enrichment

Includes Docker multi-stage build + docker-compose for Coolify deployment.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-17 11:21:11 +01:00

43 lines
1.3 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/db";
import Papa from "papaparse";
export async function GET(
req: NextRequest,
{ params }: { params: Promise<{ jobId: string }> }
) {
try {
const { jobId } = await params;
const job = await prisma.job.findUnique({
where: { id: jobId },
include: { results: { orderBy: { createdAt: "asc" } } },
});
if (!job) return NextResponse.json({ error: "Job not found" }, { status: 404 });
const rows = job.results.map(r => ({
company_name: r.companyName || "",
domain: r.domain || "",
contact_name: r.contactName || "",
contact_title: r.contactTitle || "",
email: r.email || "",
confidence_score: r.confidence !== null ? Math.round((r.confidence || 0) * 100) + "%" : "",
source_tab: job.type,
job_id: job.id,
found_at: r.createdAt.toISOString(),
}));
const csv = Papa.unparse(rows);
return new NextResponse(csv, {
headers: {
"Content-Type": "text/csv",
"Content-Disposition": `attachment; filename="leadflow-${job.type}-${jobId.slice(0, 8)}.csv"`,
},
});
} catch (err) {
console.error("GET /api/export/[jobId] error:", err);
return NextResponse.json({ error: "Failed to export" }, { status: 500 });
}
}