Skip to content

Commit

Permalink
processing/url: clean up cleanURL query exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
wukko committed May 29, 2024
1 parent 64b5990 commit 490bbf8
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/modules/processing/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,30 @@ function aliasURL(url) {
function cleanURL(url) {
assert(url instanceof URL);
const host = psl.parse(url.hostname).sld;

let stripQuery = true;

if (host === 'pinterest') {
url.hostname = 'pinterest.com'
} else if (host === 'vk' && url.pathname.includes('/clip')) {
if (url.searchParams.get('z'))
url.search = '?z=' + encodeURIComponent(url.searchParams.get('z'));
stripQuery = false;
} else if (host === 'youtube' && url.searchParams.get('v')) {
url.search = '?v=' + encodeURIComponent(url.searchParams.get('v'));
const limitQuery = (param) => {
url.search = `?${param}=` + encodeURIComponent(url.searchParams.get(param));
stripQuery = false;
}

switch (host) {
case "pinterest":
url.hostname = 'pinterest.com';
break;
case "vk":
if (url.pathname.includes('/clip') && url.searchParams.get('z')) {
limitQuery('z')
}
break;
case "youtube":
if (url.searchParams.get('v')) {
limitQuery('v')
}
break;
}

if (stripQuery) {
url.search = ''
}
Expand Down

0 comments on commit 490bbf8

Please sign in to comment.