mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 06:28:53 +00:00
feat: rename .js files to .ts
This commit is contained in:
1 parent
40bf9d926b
commit
92b1992b1a
54 files changed
No files matched your search
@@ -0,0 +1,30 @@
|
||||
exports.transformQuery = async ({ query, executionId }) => {
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'searchQueryValidator.js',
|
||||
module: 'utilValidation',
|
||||
name: 'transformQuery',
|
||||
executionId: executionId
|
||||
});
|
||||
|
||||
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|playlist)/([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 type = query.match(regex)[2];
|
||||
const trackId = query.match(regex)[3];
|
||||
query = `https://open.spotify.com/${type}/${trackId}`;
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(error, 'Error while validating or transforming Spotify url.');
|
||||
}
|
||||
}
|
||||
|
||||
return query;
|
||||
};
|
||||
Reference in new issue
Block a user