Possible function export fix?
This commit is contained in:
19
netlify/functions/validate-pr/getPlaylistIdFromUrl.ts
Normal file
19
netlify/functions/validate-pr/getPlaylistIdFromUrl.ts
Normal 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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user