diff --git a/app/main/server/horrible/horrible.js b/app/main/server/horrible/horrible.js deleted file mode 100644 index a408cb0..0000000 --- a/app/main/server/horrible/horrible.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Created by Kylart on 03/05/2017. - * - * Rip Nyaa.se May, 1st 2017 - * - */ - -const horribleApi = require('horrible-api') -const malScraper = require('mal-scraper') - -const {Logger} = require('../utils') -const horribleLogger = new Logger('Horrible (Releases)') -const malLogger = new Logger('Mal-Scraper (Releases)') - -exports.getLatest = ({query}, res) => { - const {quality} = query - - let counter = 0 - let toReturn = [] - - horribleApi.getLatest(quality.toString()).then((result) => { - for (let i = 0, l = result.length; i < l; ++i) { - const realName = result[i].name - const name = realName.split(' ').slice(1).join(' ') - const rawName = name.split(' ').slice(0, -2).join(' ') - const researchName = rawName.split(' ').join('').toLowerCase() - const ep = name.split(' ').slice(-1)[0] - const link = result[i].link - - malScraper.getInfoFromName(rawName) - .then((item) => { - item.rawName = rawName - item.researchName = researchName - item.magnetLink = link - item.ep = ep - item.synopsis = item.synopsis.length > 170 - ? item.synopsis.slice(0, 175) + '...' - : item.synopsis - - toReturn[i] = item - - ++counter - /* istanbul ignore next */ - if (counter === 18) { - horribleLogger.info('Sending latest releases.') - res.type('application/json') - res.status(200).send(JSON.stringify(toReturn)) - } - }) - .catch(/* istanbul ignore next */ (err) => { - malLogger.error('An error occurred.', err) - res.status(202).send() - }) - } - }).catch((err) => { - horribleLogger.error('An error occurred.', err) - res.status(204).send() - }) -} diff --git a/app/main/server/horrible/index.js b/app/main/server/horrible/index.js deleted file mode 100644 index d229f18..0000000 --- a/app/main/server/horrible/index.js +++ /dev/null @@ -1,7 +0,0 @@ -const {getLatest} = require('./horrible.js') - -const routes = [ - (app) => app.get('/getLatest.json', getLatest) -] - -module.exports = routes diff --git a/app/main/server/index.js b/app/main/server/index.js index d93948d..03f0e12 100644 --- a/app/main/server/index.js +++ b/app/main/server/index.js @@ -13,7 +13,6 @@ const setup = (app) => { config: require('./config'), env: require('./env'), history: require('./history'), - horrible: require('./horrible'), local: require('./local'), mal: require('./mal'), news: require('./news'), diff --git a/app/web/store/modules/releases/actions.js b/app/web/store/modules/releases/actions.js index 57b6c11..34e95ba 100644 --- a/app/web/store/modules/releases/actions.js +++ b/app/web/store/modules/releases/actions.js @@ -41,36 +41,17 @@ export default { dispatch('news/init', null, isRoot) if (state.autoRefresh === true) dispatch('autoRefresh') - } else if (status === 202) { + } else if (status === 202 || status === 204) { + // If we reach this point, it means that none of the nyaa is on. + // We'd better check both each time. + commit('setChoice', 'si') + log(`An error occurred while getting the latest releases. Retrying in 45 seconds.`) commit('setInfoSnackbar', 'Could not get the latest releases. Retrying in 45 seconds.', isRoot) setTimeout(() => { log(`Retrying to get latest releases.`) dispatch('init').catch(err => { void (err) }) }, 45 * 1000) - } else if (status === 204) { - log('nyaa.pantsu.cat does not respond... Switching to HorribleSubs.') - - commit('setChoice', 'si') - - const {data, status} = await axios.get(`getLatest.json?quality=${state.params.quality}`) - - if (status === 200) { - commit('set', {data}) - - if (state.autoRefresh === true) dispatch('autoRefresh') - } else if (status === 202) { - log(`An error occurred while getting the latest releases. Retrying in 45 seconds.`) - commit('setInfoSnackbar', 'Could not get the latest releases. Retrying in 45 seconds.', isRoot) - setTimeout(() => { - log(`Retrying to get latest releases.`) - dispatch('init').catch(err => { void (err) }) - }, 45 * 1000) - } else if (status === 204) { - log('HorribleSubs does not respond. Retrying with nyaa.si...') - - dispatch('init') - } } } } catch (e) { @@ -111,17 +92,9 @@ export default { try { const {data, status} = await axios.get('getLatestNyaa', { params: state.params }) - if (status === 200) commit('set', {data}) - else if (status === 202) { - retryLater(backUp) - } else if (status === 204) { - const {data, status} = await axios.get(`getLatest.json?quality=${state.params.quality}`) - - if (status === 200) commit('set', {data}) - else if (status === 202 || status === 204) { - retryLater(backUp) - } - } + status === 200 + ? commit('set', {data}) + : retryLater(backUp) } catch (e) { retryLater(backUp) } diff --git a/package.json b/package.json index 909513a..63a7844 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,6 @@ "electron-log": "^2.2.16", "electron-updater": "^3.0.3", "express": "^4.16.2", - "horrible-api": "^1.1.1", "is-online": "^7.0.0", "lodash": "^4.17.10", "lru-cache": "^4.0.2", diff --git a/test/server.test.js b/test/server.test.js index 80d988c..696cfaf 100644 --- a/test/server.test.js +++ b/test/server.test.js @@ -109,23 +109,6 @@ test('/saveConfig.json route exits and saves config and return 200', async t => writeFileSync(join(DIR, 'config.json'), JSON.stringify(config), 'utf-8') }) -test('/getLatest.json exits and returns 18 elements with right keys at 720p', async t => { - const { data, status } = await axios.get(`${uri}/getLatest.json?quality=720p`) - - if (status === 200) { - t.is(data.length, 18) - t.not(data[0].rawName, undefined) - t.not(data[0].researchName, undefined) - t.not(data[0].magnetLink, undefined) - t.not(data[0].picture, undefined) - } else if (status === 204 || status === 202) { - console.info('An error occurred while getting latest releases.'.yellow) - t.is(data.length, 0) - } else { - t.fail() - } -}) - test('/download Mahou Shoujo Ikusei Keikaku with HorribleSubs at 720p on nyaa.pantsu.cat exits and returns' + ' all magnets', async t => { try { @@ -229,12 +212,6 @@ test('/download Mahou Shoujo Ikusei Keikaku with HorribleSubs at 720p from ep 3 } }) -test('/getLatest.json exits and returns 204 status at 30p', async t => { - const { status } = await axios.get(`${uri}/getLatest.json?quality=30p`) - - t.is(status, 204) -}) - test('/getLatestNyaa exits and returns 18 elements with right keys at 720p on nyaa.si', async t => { const { data, status } = await axios.get(`${uri}/getLatestNyaa?quality=720p&choice=si&fansub=HorribleSubs`)