feat: Renamed validator files and added permission validator

This commit is contained in:
Marius Begby committed 2023-07-23 11:19:21 +02:00
1 parent f04937eee0
commit b68b7dac95
18 files changed
+51 -22

No files matched your search

@@ -0,0 +1,24 @@
const logger = require('../../services/logger');
exports.transformQuery = async (query) => {
if (query.startsWith('https://open.spotify.com/')) {
try {
// regex to check for country-based Spotify url
const regex = new RegExp(
'https://open.spotify.com/((?:[a-z]{2,4}-[a-z]{2,4}/)|(?:[a-z]{2,4}/))?track/([a-zA-Z0-9]+)'
);
const isCountryBased = regex.test(query);
// if country-based, transform to normal Spotify url
if (isCountryBased) {
logger.debug(`Transforming country-based Spotify url to normal Spotify url from query ${query}.`);
const trackId = query.match(regex)[2];
query = `https://open.spotify.com/track/${trackId}`;
}
} catch (error) {
logger.error(error);
}
}
return query;
};