From 0b532a1855a795edab21b8f391cba6d74854ce4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9luchu?= Date: Tue, 9 Jun 2020 17:31:24 +0200 Subject: [PATCH] Add Artists and Fix News Images --- src/api/api.js | 35 ++++++++++++++++++++++++++++++++++- src/api/index.js | 3 ++- src/api/routes/index.js | 15 +++++++++++++++ src/utils/index.js | 34 +++++++++++++++++++++++++++++++++- 4 files changed, 84 insertions(+), 3 deletions(-) diff --git a/src/api/api.js b/src/api/api.js index bef79ff..0ca3e7d 100644 --- a/src/api/api.js +++ b/src/api/api.js @@ -376,6 +376,38 @@ const getRandomTheme = async () => { }; +const getArtist = async (id) => { + + let data + let body + let promises = [] + + if (id === undefined) { + + data = await cloudscraper.get(`${BASE_THEMEMOE}artists`); + body = JSON.parse(data); + + body.map(doc => { + + promises.push({ + id: doc.artistID, + name: doc.artistName + }) + + }); + + return promises; + + } else { + + data = await cloudscraper.get(`${BASE_THEMEMOE}artists/${id}`); + body = JSON.parse(data); + + return await structureThemes(body, false, 1) + } + +}; + module.exports = { schedule, top, @@ -393,5 +425,6 @@ module.exports = { getRadioStations, getOpAndEd, getThemesSeason, - getRandomTheme + getRandomTheme, + getArtist }; diff --git a/src/api/index.js b/src/api/index.js index 0ed2f4f..54e1d78 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -30,7 +30,8 @@ router.get('/', (req, res) => { 'Radios': '/api/v2/radio', 'Themes': '/api/v2/themes/:title', 'Season Themes': '/api/v2/themeSeason/:year/:season?', - 'Random Theme': '/api/v2/randomTheme' + 'Random Theme': '/api/v2/randomTheme', + 'Artists Theme': '/api/v2/artists/:id?' } ] }); diff --git a/src/api/routes/index.js b/src/api/routes/index.js index c5481bc..d716cd9 100644 --- a/src/api/routes/index.js +++ b/src/api/routes/index.js @@ -311,4 +311,19 @@ router.get('/randomTheme', (req, res) =>{ }); +router.get('/artists/:id?', (req, res) =>{ + + let id = req.params.id; + + api.getArtist(id) + .then(artists =>{ + res.status(200).json({ + artists + }); + }).catch((err) =>{ + console.error(err); + }); + +}); + module.exports = router; diff --git a/src/utils/index.js b/src/utils/index.js index e16b77d..c39bece 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -317,7 +317,7 @@ const obtainPreviewNews = (encoded) => { .replace("httpss", "https") } else if (encoded.includes(' { }); } + } else if (task === 1) { + respFinal = body + themes = await getHeaderTheme(respFinal.themes) + + promises.push({ + title: respFinal.artistName, + season: respFinal.season, + year: respFinal.year, + series: themes, + }); + } else { + respFinal = body themes = await getThemes(respFinal.themes) @@ -376,7 +388,27 @@ const structureThemes = async (body, indv, task) => { } + return promises; + +}; + +const getHeaderTheme = async (series) => { + + let promises = [] + let data + + for(let i = 0; i <= series.length -1; i++) { + data = await getThemes(series[i].themes) + + promises.push({ + title: series[i].name, + season: series[i].season, + year: series[i].year, + themes: data, + }); + + } return promises;