Elffuss BraidHub

kikocis/osiris public

master · 1.6 KiBRawPermalink
1import { NextResponse } from 'next/server';
2
3export async function GET(req: Request) {
4 const { searchParams } = new URL(req.url);
5 const email = searchParams.get('email');
6
7 if (!email) return NextResponse.json({ error: 'Missing email parameter' }, { status: 400 });
8
9 try {
10 // We will call the breach-analytics endpoint to get deep details on what exactly was leaked.
11 const res = await fetch(`https://api.xposedornot.com/v1/breach-analytics?email=${encodeURIComponent(email)}`, {
12 headers: { 'Accept': 'application/json' }
13 });
14
15 if (res.status === 404) {
16 return NextResponse.json({ email, breached: false, breaches: [], data_exposed: [] });
17 }
18
19 if (!res.ok) throw new Error(`XposedOrNot API HTTP ${res.status}`);
20
21 const data = await res.json();
22
23 // Parse the analytics data
24 let breachList = [];
25 let dataExposed = new Set<string>();
26
27 if (data.BreachesSummary && data.BreachesSummary.site) {
28 breachList = data.BreachesSummary.site.split(';').filter(Boolean);
29 }
30
31 if (data.ExposedData && Array.isArray(data.ExposedData)) {
32 data.ExposedData.forEach((item: any) => {
33 if (item.data_classes && Array.isArray(item.data_classes)) {
34 item.data_classes.forEach((dc: string) => dataExposed.add(dc));
35 }
36 });
37 }
38
39 return NextResponse.json({
40 email,
41 breached: breachList.length > 0,
42 breaches: breachList,
43 data_exposed: Array.from(dataExposed).sort()
44 });
45 } catch (error: any) {
46 return NextResponse.json({ error: 'Leak lookup failed', detail: error.message }, { status: 502 });
47 }
48}