Skip to content

Commit

Permalink
fuzzymatching: only use default extension based first-non-query match… (
Browse files Browse the repository at this point in the history
#110)

* fuzzymatching: only use default extension based first-non-query match fuzzy matching if <=2 results, otherwise use the more extensive levdist based matching
fuzzymatching: add rule for youtube profile
deps: bump wombat 3.4.6 for style url unrewriting
part of fix for #108
  • Loading branch information
ikreymer authored Feb 26, 2023
1 parent f7aba04 commit 15f76fc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions dist/sw.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/wombat.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@peculiar/asn1-ecc": "^2.3.4",
"@peculiar/asn1-schema": "^2.3.3",
"@peculiar/x509": "^1.9.2",
"@webrecorder/wombat": "^3.4.4",
"@webrecorder/wombat": "^3.4.6",
"auto-js-ipfs": "^2.1.0",
"base64-js": "^1.5.1",
"brotli": "^1.3.3",
Expand Down
14 changes: 11 additions & 3 deletions src/fuzzymatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ const DEFAULT_RULES =
"split": "_",
"splitLast": true
},
// YouTube
{
"match": /^https?:\/\/(?:www\.)?(youtube\.com\/embed\/[^?]+)[?].*/i,
"replace": "$1",
"replace": "$1"
},
{
"match": /^(https?:\/\/(?:www\.)?)(youtube\.com\/@[^?]+)[?].*/i,
"fuzzyCanonReplace": "$1$2"
},
{
"match": /\/\/(?:www\.)?youtube(?:-nocookie)?\.com\/(get_video_info)/i,
Expand Down Expand Up @@ -122,7 +127,8 @@ const DEFAULT_RULES =
},
{
"match": /(\.(?:js|webm|mp4|gif|jpg|png|css|json|m3u8))\?.*/i,
"replace": "$1"
"replace": "$1",
"maxResults": 2
}
];

Expand Down Expand Up @@ -190,7 +196,9 @@ class FuzzyMatcher {
return null;
}

if (matchedRule && matchedRule.replace !== undefined && matchedRule.match !== undefined) {
if (matchedRule && matchedRule.replace !== undefined && matchedRule.match !== undefined &&
// if limit exists, only apply if < limit results
(!matchedRule.maxResults || results.length <= matchedRule.maxResults)) {
const match = matchedRule.match;
const replace = matchedRule.replace;
const fuzzyReqUrl = reqUrl.replace(match, replace);
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,10 @@
resolved "https://registry.yarnpkg.com/@webpack-cli/serve/-/serve-1.5.2.tgz#ea584b637ff63c5a477f6f21604b5a205b72c9ec"
integrity sha512-vgJ5OLWadI8aKjDlOH3rb+dYyPd2GTZuQC/Tihjct6F9GpXGZINo3Y/IVuZVTM1eDQB+/AOsjPUWH/WySDaXvw==

"@webrecorder/wombat@^3.4.4":
version "3.4.4"
resolved "https://registry.yarnpkg.com/@webrecorder/wombat/-/wombat-3.4.4.tgz#f01105f06eaa52f72b1ad7ecfe8290c5f5fa4ee9"
integrity sha512-2n7fG4YVs4kg1iTX84iNsV8sOrQe/Gce/1mguLdnTrNp9mW843bkKOaSPvuFjM8sa7pr3a9faVbvA3nBZZ9R3Q==
"@webrecorder/wombat@^3.4.6":
version "3.4.6"
resolved "https://registry.yarnpkg.com/@webrecorder/wombat/-/wombat-3.4.6.tgz#48c8a03b1d47789fd799f6d9d49ec1ca6c610a1f"
integrity sha512-YMGKT78B6nDOIV8irIvIPtcWGOa44/FxFXN6LqeUM8WwJrvLL3YI+pXfKYd7GYJFULNqir3Ao+nSNNrjy9PtJg==
dependencies:
warcio "^2.0.1"

Expand Down

0 comments on commit 15f76fc

Please sign in to comment.