From 362a90b02006301f90d06a29304f30a0d6243b5b Mon Sep 17 00:00:00 2001 From: FledgeShiu Date: Thu, 9 Sep 2021 16:46:36 +0800 Subject: [PATCH] chore(route): remove a broken and undocumented endpoint. (#8058) --- lib/router.js | 1 - lib/routes/matters/topics.js | 52 ------------------------------------ 2 files changed, 53 deletions(-) delete mode 100644 lib/routes/matters/topics.js diff --git a/lib/router.js b/lib/router.js index 1266f9906a..ea9edad20a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1657,7 +1657,6 @@ router.get('/zaker/:type/:id', lazyloadRouteHandler('./routes/zaker/source')); router.get('/zaker/focusread', lazyloadRouteHandler('./routes/zaker/focusread')); // Matters -router.get('/matters/topics', lazyloadRouteHandler('./routes/matters/topics')); router.get('/matters/latest/:type?', lazyloadRouteHandler('./routes/matters/latest')); router.redirect('/matters/hot', '/matters/latest/heat'); // Deprecated router.get('/matters/tags/:tid', lazyloadRouteHandler('./routes/matters/tags')); diff --git a/lib/routes/matters/topics.js b/lib/routes/matters/topics.js deleted file mode 100644 index f7e8973c6b..0000000000 --- a/lib/routes/matters/topics.js +++ /dev/null @@ -1,52 +0,0 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); - -module.exports = async (ctx) => { - const url = `https://matters.news/topics`; - - const res = await got.get(url); - const $ = cheerio.load(res.data); - const list = $('li section.container').get(); - - const proList = []; - const indexList = []; - - const out = await Promise.all( - list.map(async (item, i) => { - const $ = cheerio.load(item); - const time = $('time').attr('datetime'); - const title = $('h2').text(); - const author = $('div.content a') - .attr('href') - .replace(/\/@(.*?)\/.*/, '$1'); - const postfix = encodeURI($('div.content a').attr('href')); - const address = `https://matters.news${postfix}`; - const cache = await ctx.cache.get(address); - if (cache) { - return Promise.resolve(JSON.parse(cache)); - } - const single = { - title, - pubDate: new Date(time).toUTCString(), - author, - link: address, - guid: address, - }; - proList.push(got.get(address)); - indexList.push(i); - return Promise.resolve(single); - }) - ); - const responses = await got.all(proList); - for (let i = 0; i < responses.length; i++) { - const res = responses[i]; - const $ = cheerio.load(res.data); - out[indexList[i]].description = $('.u-content').html(); - ctx.cache.set(out[indexList[i]].link, JSON.stringify(out[i])); - } - ctx.state.data = { - title: $('title').text(), - link: url, - item: out, - }; -};