|
|
@ -2,7 +2,11 @@ import MusicBrainz from '@server/api/musicbrainz';
|
|
|
|
import { MediaType } from '@server/constants/media';
|
|
|
|
import { MediaType } from '@server/constants/media';
|
|
|
|
import Media from '@server/entity/Media';
|
|
|
|
import Media from '@server/entity/Media';
|
|
|
|
import logger from '@server/logger';
|
|
|
|
import logger from '@server/logger';
|
|
|
|
import { mapArtistResult } from '@server/models/Search';
|
|
|
|
import {
|
|
|
|
|
|
|
|
mapArtistResult,
|
|
|
|
|
|
|
|
mapReleaseGroupResult,
|
|
|
|
|
|
|
|
mapReleaseResult,
|
|
|
|
|
|
|
|
} from '@server/models/Search';
|
|
|
|
import { Router } from 'express';
|
|
|
|
import { Router } from 'express';
|
|
|
|
|
|
|
|
|
|
|
|
const musicRoutes = Router();
|
|
|
|
const musicRoutes = Router();
|
|
|
@ -11,7 +15,9 @@ musicRoutes.get('/artist/:id', async (req, res, next) => {
|
|
|
|
const mb = new MusicBrainz();
|
|
|
|
const mb = new MusicBrainz();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const artist = await mb.getArtist(req.params.id);
|
|
|
|
const artist = req.query.full
|
|
|
|
|
|
|
|
? await mb.getFullArtist(req.params.id)
|
|
|
|
|
|
|
|
: await mb.getArtist(req.params.id);
|
|
|
|
|
|
|
|
|
|
|
|
const media = await Media.getMedia(artist.id, MediaType.MUSIC);
|
|
|
|
const media = await Media.getMedia(artist.id, MediaType.MUSIC);
|
|
|
|
|
|
|
|
|
|
|
@ -29,4 +35,50 @@ musicRoutes.get('/artist/:id', async (req, res, next) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
musicRoutes.get('/release/:id', async (req, res, next) => {
|
|
|
|
|
|
|
|
const mb = new MusicBrainz();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const release = await mb.getRelease(req.params.id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const media = await Media.getMedia(release.id, MediaType.MUSIC);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res.status(200).json(await mapReleaseResult(release, media));
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
logger.debug('Something went wrong retrieving release', {
|
|
|
|
|
|
|
|
label: 'API',
|
|
|
|
|
|
|
|
errorMessage: e.message,
|
|
|
|
|
|
|
|
releaseId: req.params.id,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return next({
|
|
|
|
|
|
|
|
status: 500,
|
|
|
|
|
|
|
|
message: 'Unable to retrieve release.',
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
musicRoutes.get('/release-group/:id', async (req, res, next) => {
|
|
|
|
|
|
|
|
const mb = new MusicBrainz();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const releaseGroup = await mb.getReleaseGroup(req.params.id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const media = await Media.getMedia(releaseGroup.id, MediaType.MUSIC);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
.status(200)
|
|
|
|
|
|
|
|
.json(await mapReleaseGroupResult(releaseGroup, media));
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
logger.debug('Something went wrong retrieving release group', {
|
|
|
|
|
|
|
|
label: 'API',
|
|
|
|
|
|
|
|
errorMessage: e.message,
|
|
|
|
|
|
|
|
releaseGroupId: req.params.id,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return next({
|
|
|
|
|
|
|
|
status: 500,
|
|
|
|
|
|
|
|
message: 'Unable to retrieve release group.',
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
export default musicRoutes;
|
|
|
|
export default musicRoutes;
|
|
|
|