diff --git a/server/index.js b/server/index.js index db11113..884e661 100644 --- a/server/index.js +++ b/server/index.js @@ -3,8 +3,6 @@ const compression = require('compression') const cors = require('cors') const setupIo = require('./io') -const autocomplete = require('./routes/autocomplete') -const bif = require('./routes/bif') const opening = require('./routes/opening') const mal = require('./routes/mal') @@ -29,8 +27,6 @@ app.post('/update/:token', (req, res) => { io.emit('app-update') res.send({status: 'ok'}) }) -app.get('/autocomplete/:country', autocomplete) -app.get('/bif', bif) app.get('/opening', opening) app.use('/mal', mal) diff --git a/server/routes/autocomplete.js b/server/routes/autocomplete.js deleted file mode 100644 index f7eea9c..0000000 --- a/server/routes/autocomplete.js +++ /dev/null @@ -1,27 +0,0 @@ -const axios = require('axios') - -function autocompleteHandler (req, res) { - const {country} = req.params - axios.all([ - axios.get(`http://because.moe/json/${country}`), - axios.get('http://www.crunchyroll.com/ajax/?req=RpcApiSearch_GetSearchCandidates') - ]).then(axios.spread((a, b) => { - const moe = a.data.shows - const cr = JSON.parse(b.data.substring(10, b.data.length - 2)).data - - const filtered = cr - .filter((c) => c.type === 'Series' && !!(moe.find((m) => m.sites.crunchyroll && m.sites.crunchyroll === `http://www.crunchyroll.com${c.link}`))) - .map((c) => ({ - name: c.name, - id: c.id, - image: c.img - })) - - res.send(filtered) - })).catch((err) => { - console.error(err.message) - res.status(500).send('something went wrong') - }) -} - -module.exports = autocompleteHandler diff --git a/server/routes/bif.js b/server/routes/bif.js deleted file mode 100644 index 3d758c5..0000000 --- a/server/routes/bif.js +++ /dev/null @@ -1,18 +0,0 @@ -const axios = require('axios') -const url = require('url') - -function bifHandler (req, res) { - const {bif} = req.query - if (!bif) return res.end() - const {hostname} = url.parse(bif) - if (!hostname.endsWith('crunchyroll.com')) return res.end() - - res.type('application/octet-stream') - axios.get(bif, { - responseType: 'stream' - }) - .then(({data}) => data.pipe(res)) - .catch(() => res.end()) -} - -module.exports = bifHandler diff --git a/server/routes/opening.js b/server/routes/opening.js index 12d9fae..d52ab8c 100644 --- a/server/routes/opening.js +++ b/server/routes/opening.js @@ -1,12 +1,12 @@ const axios = require('axios') const cheerio = require('cheerio') -function openingHandler (req, res) { +async function openingHandler (req, res) { const {search} = req.query if (!search) return res.send({result: null}) - axios.post('https://themes.moe/includes/anime_search.php', `search=-1&name=${search}`).then(({data}) => { - const [html, id] = data + try { + const {data: [html, id]} = await axios.post('https://themes.moe/includes/anime_search.php', `search=-1&name=${search}`) if (!id) return res.send({result: null}) const $ = cheerio.load(html) @@ -14,7 +14,10 @@ function openingHandler (req, res) { const result = openings[Math.floor(Math.random() * openings.length)] res.send({result}) - }) + } catch (err) { + console.error(err.message) + res.send({result: null}) + } } module.exports = openingHandler