@@ -11,6 +11,7 @@ import {
1111import { ScopedSeed } from "./seeds.js" ;
1212import { Frame } from "puppeteer-core" ;
1313import { interpolateFilename , UploadResult } from "./storage.js" ;
14+ import normalizeUrl , { Options as NormamlizeUrlOptions } from "normalize-url" ;
1415
1516// ============================================================================
1617export enum LoadState {
@@ -28,6 +29,20 @@ export enum QueueState {
2829 DUPE_URL = 2 ,
2930}
3031
32+ // ============================================================================
33+ const normalizeUrlOpts : NormamlizeUrlOptions = {
34+ defaultProtocol : "https" ,
35+ stripAuthentication : false ,
36+ stripTextFragment : false ,
37+ stripWWW : false ,
38+ stripHash : false ,
39+ removeTrailingSlash : false ,
40+ removeSingleSlash : false ,
41+ removeExplicitPort : false ,
42+ sortQueryParameters : true ,
43+ removePath : false ,
44+ } ;
45+
3146// ============================================================================
3247// treat 0 or 206 as 200 for purposes of dedup
3348function normalizeDedupStatus ( status : number ) : number {
@@ -675,7 +690,6 @@ return inx;
675690 return res >= 3 ;
676691 }
677692
678- //async addToQueue({url : string, seedId, depth = 0, extraHops = 0} = {}, limit = 0) {
679693 async addToQueue (
680694 {
681695 url,
@@ -687,6 +701,7 @@ return inx;
687701 } : QueueEntry ,
688702 limit = 0 ,
689703 ) {
704+ url = normalizeUrl ( url , normalizeUrlOpts ) ;
690705 const added = this . _timestamp ( ) ;
691706 const data : QueueEntry = { added, url, seedId, depth, extraHops } ;
692707
@@ -1012,6 +1027,7 @@ return inx;
10121027 }
10131028
10141029 async addIfNoDupe ( key : string , url : string , status : number ) {
1030+ url = normalizeUrl ( url , normalizeUrlOpts ) ;
10151031 return (
10161032 ( await this . redis . sadd ( key , normalizeDedupStatus ( status ) + "|" + url ) ) ===
10171033 1
0 commit comments