mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 14:38:49 +00:00
fix: annotated util validation functions
This commit is contained in:
1 parent
d38ed18842
commit
1ae9503477
5 files changed
+64
-50
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import loggerModule from '../../services/logger';
|
||||
import { TransformQueryParams } from '../../types/utilTypes';
|
||||
|
||||
export const transformQuery = async ({ query, executionId }) => {
|
||||
export const transformQuery = async ({ query, executionId }: TransformQueryParams) => {
|
||||
const logger = loggerModule.child({
|
||||
source: 'searchQueryValidator.js',
|
||||
module: 'utilValidation',
|
||||
@@ -11,7 +12,7 @@ export const transformQuery = async ({ query, executionId }) => {
|
||||
if (query.startsWith('https://open.spotify.com/')) {
|
||||
try {
|
||||
// regex to check for country-based Spotify url
|
||||
const regex = new RegExp(
|
||||
const regex: RegExp = 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);
|
||||
@@ -19,9 +20,12 @@ export const transformQuery = async ({ query, executionId }) => {
|
||||
// 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}`;
|
||||
const matches = query.match(regex);
|
||||
if (matches) {
|
||||
const type = matches[2];
|
||||
const trackId = matches[3];
|
||||
query = `https://open.spotify.com/${type}/${trackId}`;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(error, 'Error while validating or transforming Spotify url.');
|
||||
|
||||
Reference in new issue
Block a user