Show a rename warning for valid playlist URLs

This commit is contained in:
Maciej Pędzich
2023-01-27 14:22:17 +01:00
parent b79596acef
commit 5e82956fcd
3 changed files with 62 additions and 33 deletions

19
getPlaylistIdFromUrl.ts Normal file
View File

@@ -0,0 +1,19 @@
export const getPlaylistIdFromUrl = (url: string) => {
try {
const urlObject = new URL(url);
const [collectionName, playlistId] = urlObject.pathname
.split('/')
.filter(Boolean);
const isValidPlaylistUrl =
urlObject.hostname === 'open.spotify.com' &&
collectionName === 'playlist' &&
playlistId;
if (!isValidPlaylistUrl) return null;
return playlistId;
} catch {
return null;
}
};