mirror of
https://github.com/BluemediaDev/muse.git
synced 2025-05-11 12:21:37 +02:00
Fix URL cleaning: youtube IDs are not valid URLs
This commit is contained in:
parent
1212ffc102
commit
e59db76694
2 changed files with 20 additions and 10 deletions
18
src/utils/url.ts
Normal file
18
src/utils/url.ts
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue