Skip to content

Commit

Permalink
✨ feat: Update - October 3rd, 2024 (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
kms0219kms authored Oct 3, 2024
2 parents 1cd6577 + 02bb6e7 commit 731b0a4
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 185 deletions.
14 changes: 13 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,24 @@
"plugin:tailwindcss/recommended"
],
"rules": {
"react": {
"version": "detect"
},
"formComponents": ["Form"],
"linkComponents": [
{ "name": "Link", "linkAttribute": "to" },
{ "name": "NavLink", "linkAttribute": "to" }
],
"import/resolver": {
"typescript": {}
},
"tailwindcss/classnames-order": [
"warn",
{
"officialSorting": true
}
],
"implicit-arrow-linebreak": "off"
"implicit-arrow-linebreak": "off",
"operator-linebreak": "off"
}
}
8 changes: 4 additions & 4 deletions apps/backend/src/services/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ export class SearchService extends UnimplementedSearchService {
const r = await requestToMxm(parsedMxmUrl);
if (!r.ok) {
throw new Error(
"The track hasn't been imported yet. Please try again after 1-5 minutes.\n" +
'If the problem persists after 15 minutes, please contact to the developer.',
"The track hasn't been imported yet. Please request Mxm team to import this track.\n" +
'You can request them by sending the track URL in #catalogue-issues in Community Slack.',
);
}

Expand All @@ -196,8 +196,8 @@ export class SearchService extends UnimplementedSearchService {
const r = await requestToMxm(parsedMxmUrl);
if (!r.ok) {
throw new Error(
"The album hasn't been imported yet. Please try again after 1-5 minutes.\n" +
'If the problem persists after 15 minutes, please contact to the developer.',
"The album hasn't been imported yet. Please request Mxm team to import this album.\n" +
'You can request them by sending the album URL in #catalogue-issues in Community Slack.',
);
}

Expand Down
75 changes: 43 additions & 32 deletions apps/backend/src/utils/parseUrl.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,54 @@ const STOREFRONT_REGEX =
const MXM_PARSE_REGEX =
/album\/([^?]+\/[^?]+)|album\/(\d+)|lyrics\/([^?]+\/[^?]+)/;

const ISRC_REGEX = /^[A-Z]{2}-?\w{3}-?\d{2}-?\d{5}$/;

export function parseAppleUrl(url: string): IAppleMusicUrl {
const urlObj = new URL(url);
const path = urlObj.pathname.split('/');
path.shift(); // remove the first empty string
if (!ISRC_REGEX.test(url)) {
const urlObj = new URL(url);
const path = urlObj.pathname.split('/');
path.shift(); // remove the first empty string

// URL: https://music.apple.com/kr/album/blue-ep/1748504604
// id: 1748504604
// storefront: kr
// type: EAplleMusicUrlType.ALBUM
// URL: https://music.apple.com/kr/album/blue-ep/1748504604
// id: 1748504604
// storefront: kr
// type: EAplleMusicUrlType.ALBUM

if (path[0].length !== 2) {
// assume the country code is `us`
path.unshift('us');
}
if (path[0].length !== 2) {
// assume the country code is `us`
path.unshift('us');
}

if (
urlObj.hostname !== 'music.apple.com' ||
path.length < 4 ||
path.length > 5 ||
!STOREFRONT_REGEX.test(path[0]) ||
!['album', 'song'].includes(path[1]) ||
!/^\d+$/.test(path[path.length - 1])
) {
throw new BadRequestError(
'Unsupported URL format. Please check the URL again.\n' +
'Working example: https://music.apple.com/kr/album/blue-ep/1748504604',
);
}
if (
urlObj.hostname !== 'music.apple.com' ||
path.length < 4 ||
path.length > 5 ||
!STOREFRONT_REGEX.test(path[0]) ||
!['album', 'song'].includes(path[1]) ||
!/^\d+$/.test(path[path.length - 1])
) {
throw new BadRequestError(
'Unsupported URL format. Please check the URL again.\n' +
'Working example: https://music.apple.com/kr/album/blue-ep/1748504604',
);
}

return {
id: path[path.length - 1],
storefront: path[0],
type: EAppleMusicUrlType[
path[1].toUpperCase() as keyof typeof EAppleMusicUrlType
],
url,
};
return {
id: path[path.length - 1],
storefront: path[0],
type: EAppleMusicUrlType[
path[1].toUpperCase() as keyof typeof EAppleMusicUrlType
],
url,
};
} else {
return {
id: url, // ISRC
storefront: 'us',
type: EAppleMusicUrlType.SONG,
url: 'ISRC',
};
}
}

export function parseMxmUrl(url: string): IMxmUrl {
Expand Down
8 changes: 7 additions & 1 deletion apps/backend/src/utils/request.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import { EMxmUrlType, IMxmUrl } from '../types/mxmUrl.type';
import { getAppleDeveloperToken } from './appleToken.util';

export async function requestToApple(data: IAppleMusicUrl) {
const url = `https://api.music.apple.com/v1/catalog/${data.storefront}/${data.type}/${data.id}`;
let url = `https://api.music.apple.com/v1/catalog/${data.storefront}/${data.type}`;

if (data.url === 'ISRC') {
url += `?filter[isrc]=${data.id}`;
} else {
url += `/${data.id}`;
}

return fetch(url, {
headers: {
Expand Down
114 changes: 0 additions & 114 deletions apps/frontend/.eslintrc.cjs

This file was deleted.

Loading

0 comments on commit 731b0a4

Please sign in to comment.