Fix URL cleaning: youtube IDs are not valid URLs

This commit is contained in:
Luis Ávila 2021-09-14 19:07:43 +01:00
parent 1212ffc102
commit e59db76694
No known key found for this signature in database
GPG key ID: 88BC24179A6B16E0
2 changed files with 20 additions and 10 deletions

18
src/utils/url.ts Normal file
View file

@ -0,0 +1,18 @@
import {URL} from 'url';
export const cleanUrl = (url: string) => {
try {
// Clean URL
const u = new URL(url);
for (const [name] of u.searchParams) {
if (name !== 'v') {
u.searchParams.delete(name);
}
}
return u.toString();
}
catch (_: unknown) {
return url;
}
}