Skip to content

Commit 61e3dfc

Browse files
authored
Merge pull request dubinc#805 from dubinc/fix-pangea-anthropic
Skip Pangea & Anthropic if API Keys are not defined
2 parents 2d2aa94 + 1aeaf75 commit 61e3dfc

5 files changed

Lines changed: 45 additions & 28 deletions

File tree

apps/web/.env.example

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,8 @@ ANTHROPIC_API_KEY=
106106
NEXT_PUBLIC_IS_DUB=
107107

108108
# For cron jobs
109-
CRON_SECRET=
109+
CRON_SECRET=
110+
111+
# Pangea - Retrieve reputation for a domain.
112+
# Get your Pange API Key here: https://pangea.cloud/docs/admin-guide/tokens/
113+
PANGEA_API_KEY=

apps/web/app/api/ai/completion/route.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ export async function POST(req: NextRequest) {
2626
const { workspaceId } = searchParams;
2727
const workspace = await getWorkspaceViaEdge(workspaceId);
2828

29+
if (!anthropic) {
30+
console.error("Anthropic is not configured. Skipping the request.");
31+
return new Response(null, { status: 200 });
32+
}
33+
2934
if (!workspace) {
3035
return new Response("Workspace not found", { status: 404 });
3136
}

apps/web/app/api/ai/generate-support-title/route.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import { NextRequest } from "next/server";
88
export const runtime = "edge";
99

1010
export async function POST(req: NextRequest) {
11+
if (!anthropic) {
12+
console.error("Anthropic is not configured. Skipping the request.");
13+
return new Response(null, { status: 200 });
14+
}
15+
1116
try {
1217
const session = await getToken({
1318
req,

apps/web/lib/anthropic.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Anthropic from "@anthropic-ai/sdk";
22

3-
export const anthropic = new Anthropic({
4-
apiKey: process.env.ANTHROPIC_API_KEY || "",
5-
});
3+
const apiKey = process.env.ANTHROPIC_API_KEY;
4+
5+
export const anthropic = apiKey ? new Anthropic({ apiKey }) : null;

apps/web/lib/api/links/process-link.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -323,35 +323,38 @@ async function maliciousLinkCheck(url: string) {
323323
return false;
324324
}
325325

326-
try {
327-
const response = await getPangeaDomainIntel(domain);
326+
// Check with Pangea for domain reputation
327+
if (process.env.PANGEA_API_KEY) {
328+
try {
329+
const response = await getPangeaDomainIntel(domain);
328330

329-
const verdict = response.result.data[apexDomain].verdict;
330-
console.log("Pangea verdict for domain", apexDomain, verdict);
331+
const verdict = response.result.data[apexDomain].verdict;
332+
console.log("Pangea verdict for domain", apexDomain, verdict);
331333

332-
if (verdict === "benign") {
333-
await updateConfig({
334-
key: "whitelistedDomains",
335-
value: domain,
336-
});
337-
return false;
338-
} else if (verdict === "malicious" || verdict === "suspicious") {
339-
await Promise.all([
340-
updateConfig({
341-
key: "domains",
334+
if (verdict === "benign") {
335+
await updateConfig({
336+
key: "whitelistedDomains",
342337
value: domain,
343-
}),
344-
log({
345-
message: `Suspicious link detected via Pangea → ${url}`,
346-
type: "links",
347-
mention: true,
348-
}),
349-
]);
338+
});
339+
return false;
340+
} else if (verdict === "malicious" || verdict === "suspicious") {
341+
await Promise.all([
342+
updateConfig({
343+
key: "domains",
344+
value: domain,
345+
}),
346+
log({
347+
message: `Suspicious link detected via Pangea → ${url}`,
348+
type: "links",
349+
mention: true,
350+
}),
351+
]);
350352

351-
return true;
353+
return true;
354+
}
355+
} catch (e) {
356+
console.error("Error checking domain with Pangea", e);
352357
}
353-
} catch (e) {
354-
console.error("Error checking domain with Pangea", e);
355358
}
356359

357360
return false;

0 commit comments

Comments
 (0)