-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
61 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import fetchDomainsByTechnology from "@/lib/db/domains-by-technology"; | ||
import { NextRequest } from "next/server"; | ||
|
||
export async function GET( | ||
request: NextRequest, | ||
context: { | ||
}, | ||
) { | ||
const technology = request.nextUrl.searchParams.get("technology"); | ||
if (!technology) { | ||
return Response.json({ | ||
error: "Missing required parameter: technology", | ||
}, { | ||
status: 400, | ||
}); | ||
} | ||
|
||
const data = await fetchDomainsByTechnology(technology, 100); | ||
return Response.json({ | ||
// We really need to decide on some sort of way to enforce a contract here. | ||
// Maybe zod-openapi? | ||
data: data.data.map((item) => { | ||
return { | ||
domain: item.domain, | ||
creation_date: item.creation_date, | ||
} | ||
}).sort((a, b) => b.creation_date.getTime() - a.creation_date.getTime()), | ||
count: data.count, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { db } from "@/lib/db/connection"; | ||
|
||
const fetchDomainsByTechnology = async (technology: string, limit: number) => { | ||
const data = process.env.DISABLE_DATABASE | ||
? { data: [], count: 0 } | ||
: await db | ||
.selectFrom("detected_technologies") | ||
.where("technology", "=", technology) | ||
.selectAll() | ||
.distinctOn("domain") | ||
.execute() | ||
.then((results) => { | ||
return { | ||
data: results.slice(0, limit), | ||
count: results.length, | ||
}; | ||
}); | ||
|
||
return data; | ||
}; | ||
|
||
export default fetchDomainsByTechnology; |