mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-01 14:38:48 +00:00
fix: check for duplicate /track/id in spotify url and trim
This commit is contained in:
1 parent
5601767806
commit
b3b73ad49f
1 file changed
+8
@@ -27,6 +27,14 @@ export const transformQuery = ({ query, executionId }: TransformQueryParams) =>
|
||||
query = `https://open.spotify.com/${type}/${trackId}`;
|
||||
}
|
||||
}
|
||||
|
||||
// if /track/id is in url TWICE, remove the second one, e.g. https://open.spotify.com/track/123/track/123
|
||||
const trackIdRegex: RegExp = new RegExp('https://open.spotify.com/track/([a-zA-Z0-9]+)');
|
||||
const trackIdMatches: RegExpMatchArray | null = query.match(trackIdRegex);
|
||||
if (trackIdMatches) {
|
||||
const trackId: string = trackIdMatches[1];
|
||||
query = `https://open.spotify.com/track/${trackId}`;
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(error, 'Error while validating or transforming Spotify url.');
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user