feat: API Keys via Umgebungsvariablen konfigurierbar
- Neuer getApiKey() Helper: prüft zuerst ENV-Vars, dann DB - Alle Job-Routes nutzen getApiKey() statt direktem DB-Lookup - Credentials-Status berücksichtigt ENV-Vars (Sidebar-Haken) - .env.local.example: Platzhalter für alle 4 API Keys Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { decrypt } from "@/lib/utils/encryption";
|
||||
import { getApiKey } from "@/lib/utils/apiKey";
|
||||
import { searchPlacesMultiQuery } from "@/lib/services/googlemaps";
|
||||
import { bulkSearchDomains, type DecisionMakerCategory } from "@/lib/services/anymailfinder";
|
||||
|
||||
@@ -20,17 +20,11 @@ export async function POST(req: NextRequest) {
|
||||
return NextResponse.json({ error: "No search queries provided" }, { status: 400 });
|
||||
}
|
||||
|
||||
const mapsCredential = await prisma.apiCredential.findUnique({ where: { service: "googlemaps" } });
|
||||
if (!mapsCredential?.value) {
|
||||
return NextResponse.json({ error: "Google Maps API key not configured" }, { status: 400 });
|
||||
}
|
||||
const mapsApiKey = decrypt(mapsCredential.value);
|
||||
const mapsApiKey = await getApiKey("googlemaps");
|
||||
if (!mapsApiKey) return NextResponse.json({ error: "Google Maps API key not configured" }, { status: 400 });
|
||||
|
||||
if (enrichEmails) {
|
||||
const anymailCred = await prisma.apiCredential.findUnique({ where: { service: "anymailfinder" } });
|
||||
if (!anymailCred?.value) {
|
||||
return NextResponse.json({ error: "Anymailfinder API key not configured" }, { status: 400 });
|
||||
}
|
||||
if (enrichEmails && !(await getApiKey("anymailfinder"))) {
|
||||
return NextResponse.json({ error: "Anymailfinder API key not configured" }, { status: 400 });
|
||||
}
|
||||
|
||||
const job = await prisma.job.create({
|
||||
@@ -98,10 +92,8 @@ async function runMapsEnrich(
|
||||
|
||||
// 3. Optionally enrich with Anymailfinder
|
||||
if (params.enrichEmails && places.length > 0) {
|
||||
const anymailCred = await prisma.apiCredential.findUnique({ where: { service: "anymailfinder" } });
|
||||
if (!anymailCred?.value) throw new Error("Anymailfinder key missing");
|
||||
|
||||
const anymailKey = decrypt(anymailCred.value);
|
||||
const anymailKey = await getApiKey("anymailfinder");
|
||||
if (!anymailKey) throw new Error("Anymailfinder key missing");
|
||||
const domains = places.filter(p => p.domain).map(p => p.domain!);
|
||||
|
||||
// Map domain → placeId for updating results
|
||||
|
||||
Reference in New Issue
Block a user