File tree Expand file tree Collapse file tree 5 files changed +61
-7
lines changed Expand file tree Collapse file tree 5 files changed +61
-7
lines changed Original file line number Diff line number Diff line change
1
+ import fetch from "@/lib/data" ;
2
+ import { db } from "@/lib/db/connection" ;
3
+ import { reify } from "@/lib/db/domains" ;
4
+ import { sql } from "kysely" ;
5
+ import pino from "pino" ;
6
+
7
+ const logger = pino ( {
8
+ name : "cron-refresh" ,
9
+ } ) ;
10
+
11
+ const RAW_QUERY = sql < {
12
+ domain : string ;
13
+ } > `
14
+ select domain from tranco TABLESAMPLE system (0.01)
15
+ ` ;
16
+
17
+ const getRandomDomains = async ( ) => {
18
+ const domains = await RAW_QUERY . execute ( db ) ;
19
+ return domains . rows . map ( ( row ) => row . domain ) ;
20
+ } ;
21
+
22
+ const MAXIMUM_DOMAINS = 10 ;
23
+
24
+ export async function GET (
25
+ request : Request ,
26
+ context : {
27
+ params : {
28
+ domain : string ;
29
+ } ;
30
+ } ,
31
+ ) {
32
+ const domains = await getRandomDomains ( ) ;
33
+ const selectedDomains = domains . slice ( 0 , MAXIMUM_DOMAINS ) ;
34
+ await Promise . all ( selectedDomains . map ( async ( domain ) => {
35
+ logger . info ( {
36
+ message : "refresh.started" ,
37
+ domain : domain ,
38
+ } ) ;
39
+ const rawResponse = await fetch ( domain ) ;
40
+ await reify ( domain , rawResponse ) ;
41
+ } ) ) ;
42
+
43
+ return Response . json ( {
44
+ domains : selectedDomains ,
45
+ } ) ;
46
+ }
Original file line number Diff line number Diff line change @@ -20,7 +20,6 @@ export async function GET(
20
20
) {
21
21
const rawResponse = await fetch ( context . params . domain ) ;
22
22
await reify ( context . params . domain , rawResponse ) ;
23
- console . log ( rawResponse . detected_technologies ) ;
24
23
25
24
return Response . json ( {
26
25
domain : context . params . domain ,
Original file line number Diff line number Diff line change @@ -80,14 +80,15 @@ export default async function TechnologyPage({
80
80
const trancoCount = process . env . DISABLE_DATABASE
81
81
? 0
82
82
: await db
83
- . selectFrom ( "tranco " )
83
+ . selectFrom ( "affiliations " )
84
84
. innerJoin (
85
85
"detected_technologies" ,
86
- "tranco .domain" ,
86
+ "affiliations .domain" ,
87
87
"detected_technologies.domain"
88
88
)
89
89
. where ( "detected_technologies.technology" , "=" , params . identifier )
90
- . select ( db . fn . count ( "tranco.domain" ) . as ( "count" ) )
90
+ . where ( "affiliations.identifier" , "=" , "tranco" )
91
+ . select ( db . fn . count ( "affiliations.domain" ) . as ( "count" ) )
91
92
. executeTakeFirst ( )
92
93
. then ( ( result ) => Number ( result ?. count || 0 ) ) ;
93
94
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ const GENERIC_SOCIAL_MEDIA_PROVIDER = (html: string) => {
28
28
const username = match [ match . length - 1 ] ;
29
29
return [
30
30
{
31
- identifier : potentialMatch ?. identifier ,
31
+ identifier : potentialMatch ?. identifier as string ,
32
32
metadata : {
33
33
username : username . split ( "?" ) [ 0 ] ,
34
34
} ,
@@ -119,7 +119,7 @@ const JSONLD_RULE = (html: string) => {
119
119
) ;
120
120
if ( service ) {
121
121
return {
122
- identifier : service . identifier . split ( "?" ) [ 0 ] ,
122
+ identifier : service . identifier . split ( "?" ) [ 0 ] as string ,
123
123
metadata : {
124
124
username : url . split ( "/" ) . pop ( ) || "" ,
125
125
} ,
@@ -199,7 +199,7 @@ const SUBDOMAIN_RULE = (html: string, domain: string) => {
199
199
200
200
const RULES : ( ( html : string , domain : string ) => DetectedTechnology [ ] ) [ ] = [
201
201
...Object . values ( REGISTRY ) . map ( ( service ) => {
202
- return ( html : string , domain : string ) => {
202
+ return ( html : string ) => {
203
203
const potentialMatches = service . substrings ?. filter ( ( substring ) =>
204
204
html . includes ( substring ) ,
205
205
) ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "crons" : [
3
+ {
4
+ "path" : " /api/crons/refresh" ,
5
+ "schedule" : " * * * * *"
6
+ }
7
+ ]
8
+ }
You can’t perform that action at this time.
0 commit comments