diff --git a/.eslintrc.json b/.eslintrc.json index f7f4dd8966..007cb5c556 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -2,7 +2,7 @@ "extends": ["eslint:recommended", "plugin:prettier/recommended", "plugin:yml/recommended"], "plugins": ["prettier"], "parserOptions": { - "ecmaVersion": 2020, + "ecmaVersion": "latest", "sourceType": "module" }, "env": { @@ -65,6 +65,7 @@ "no-prototype-builtins": 0, "no-new-func": 2, "require-await": 2, + "no-return-await": 2, "prefer-arrow-callback": 2, "object-shorthand": 2, "yml/quotes": [ diff --git a/.github/workflows/pr-lint.yml b/.github/workflows/pr-lint.yml index 7ef28c4eaf..d0493daaaf 100644 --- a/.github/workflows/pr-lint.yml +++ b/.github/workflows/pr-lint.yml @@ -23,6 +23,9 @@ jobs: if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }} runs-on: ubuntu-latest timeout-minutes: 5 + permissions: + contents: read + security-events: write steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 diff --git a/lib/routes/fanxinzhui/latest.js b/lib/routes/fanxinzhui/latest.js index 37de7b2e60..28af5948be 100644 --- a/lib/routes/fanxinzhui/latest.js +++ b/lib/routes/fanxinzhui/latest.js @@ -29,19 +29,18 @@ module.exports = async (ctx) => { .get(); const items = await Promise.all( - list.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = cheerio.load(detailResponse.data); + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); - item.description = content('.middle_box').html(); + item.description = content('.middle_box').html(); - return item; - }) + return item; + }) ) ); diff --git a/lib/routes/fashionnetwork/headline.js b/lib/routes/fashionnetwork/headline.js index e0e38bf33d..4872f00f23 100644 --- a/lib/routes/fashionnetwork/headline.js +++ b/lib/routes/fashionnetwork/headline.js @@ -31,21 +31,20 @@ module.exports = async (ctx) => { .get(); const items = await Promise.all( - list.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = cheerio.load(detailResponse.data); + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); - content('.newsTitle, .ads').remove(); + content('.newsTitle, .ads').remove(); - item.description = content('div[itemprop="text"]').html(); + item.description = content('div[itemprop="text"]').html(); - return item; - }) + return item; + }) ) ); diff --git a/lib/routes/fashionnetwork/news.js b/lib/routes/fashionnetwork/news.js index 105334e7b6..211ef03a1b 100644 --- a/lib/routes/fashionnetwork/news.js +++ b/lib/routes/fashionnetwork/news.js @@ -43,21 +43,20 @@ module.exports = async (ctx) => { .get(); const items = await Promise.all( - list.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = cheerio.load(detailResponse.data); + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); - content('.newsTitle, .ads').remove(); + content('.newsTitle, .ads').remove(); - item.description = content('div[itemprop="text"]').html(); + item.description = content('div[itemprop="text"]').html(); - return item; - }) + return item; + }) ) ); diff --git a/lib/routes/ncm/djradio.js b/lib/routes/ncm/djradio.js index 50512b0063..a6ca1d3b2d 100644 --- a/lib/routes/ncm/djradio.js +++ b/lib/routes/ncm/djradio.js @@ -6,8 +6,8 @@ const path = require('path'); module.exports = async (ctx) => { const id = ctx.params.id; - const ProcessFeed = async (limit, offset) => - await got({ + const ProcessFeed = (limit, offset) => + got({ method: 'post', url: 'https://music.163.com/api/dj/program/byradio', headers: { diff --git a/lib/routes/questmobile/report.js b/lib/routes/questmobile/report.js index e72835bd85..214e10262c 100644 --- a/lib/routes/questmobile/report.js +++ b/lib/routes/questmobile/report.js @@ -94,23 +94,22 @@ module.exports = async (ctx) => { })); const items = await Promise.all( - list.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = cheerio.load(detailResponse.data); + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); - content('img[_ngcontent-c11]').each(function () { - content(this).attr('alt', ''); - }); + content('img[_ngcontent-c11]').each(function () { + content(this).attr('alt', ''); + }); - item.description = content('.text').html(); + item.description = content('.text').html(); - return item; - }) + return item; + }) ) ); diff --git a/lib/routes/rss3/blog.js b/lib/routes/rss3/blog.js index efc789a978..b2f1c99c50 100644 --- a/lib/routes/rss3/blog.js +++ b/lib/routes/rss3/blog.js @@ -22,20 +22,19 @@ module.exports = async (ctx) => { .get(); const items = await Promise.all( - list.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = cheerio.load(detailResponse.data); + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); - item.description = content('.post-content').html(); - item.pubDate = Date.parse(content('small time').attr('datetime')); + item.description = content('.post-content').html(); + item.pubDate = Date.parse(content('small time').attr('datetime')); - return item; - }) + return item; + }) ) ); diff --git a/lib/utils/wechat-mp.js b/lib/utils/wechat-mp.js index b2c743a24f..c431cdf374 100644 --- a/lib/utils/wechat-mp.js +++ b/lib/utils/wechat-mp.js @@ -187,9 +187,9 @@ const normalizeUrl = (url, bypassHostCheck = false) => { * @param {boolean} bypassHostCheck - Whether to bypass host check. * @return {Promise} - An object containing the article and its metadata. */ -const fetchArticle = async (ctx, url, bypassHostCheck = false) => { +const fetchArticle = (ctx, url, bypassHostCheck = false) => { url = normalizeUrl(url, bypassHostCheck); - return await ctx.cache.tryGet(url, async () => { + return ctx.cache.tryGet(url, async () => { const response = await got(url); const $ = cheerio.load(response.data); diff --git a/lib/v2/52hrtt/index.js b/lib/v2/52hrtt/index.js index 7eac5e4821..9bb7fc98c0 100644 --- a/lib/v2/52hrtt/index.js +++ b/lib/v2/52hrtt/index.js @@ -33,19 +33,18 @@ module.exports = async (ctx) => { })); const items = await Promise.all( - list.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = cheerio.load(detailResponse.data); + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); - item.description = content('.info-content').html(); + item.description = content('.info-content').html(); - return item; - }) + return item; + }) ) ); diff --git a/lib/v2/52hrtt/symposium.js b/lib/v2/52hrtt/symposium.js index 1330490f67..8122c1d442 100644 --- a/lib/v2/52hrtt/symposium.js +++ b/lib/v2/52hrtt/symposium.js @@ -33,19 +33,18 @@ module.exports = async (ctx) => { })); const items = await Promise.all( - list.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = cheerio.load(detailResponse.data); + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); - item.description = content('.info-content').html(); + item.description = content('.info-content').html(); - return item; - }) + return item; + }) ) ); diff --git a/lib/v2/abmedia/category.js b/lib/v2/abmedia/category.js index 4eb435f250..06a3a4e3ca 100644 --- a/lib/v2/abmedia/category.js +++ b/lib/v2/abmedia/category.js @@ -5,7 +5,7 @@ const rootUrl = 'https://www.abmedia.io'; const cateAPIUrl = `${rootUrl}/wp-json/wp/v2/categories`; const postsAPIUrl = `${rootUrl}/wp-json/wp/v2/posts`; -const getCategoryId = async (category) => await got.get(`${cateAPIUrl}?slug=${category}`).then((res) => res.data[0].id); +const getCategoryId = (category) => got.get(`${cateAPIUrl}?slug=${category}`).then((res) => res.data[0].id); module.exports = async (ctx) => { const category = ctx.params.category ?? 'technology-development'; diff --git a/lib/v2/ally/rail.js b/lib/v2/ally/rail.js index a0ddae442f..a0a8149e81 100644 --- a/lib/v2/ally/rail.js +++ b/lib/v2/ally/rail.js @@ -54,49 +54,48 @@ module.exports = async (ctx) => { .slice(0, ctx.query.limit || 20); items = await Promise.all( - items.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const response = await got(item.link); - const $ = cheerio.load(response.data); - // fix weird format - let description = ''; - const content = $('div.content_all'); - if (content.length) { - content - .eq(content.length - 1) // some pages have "summary" - .contents() - .each((_, child) => { - const $child = $(child); - let innerHtml; - if (child.name === 'div') { - innerHtml = $child.html(); - innerHtml = innerHtml && innerHtml.trim(); - description += !innerHtml || innerHtml === ' ' ? (description ? '
' : '') : innerHtml; - } else { - // bare text node or something else - description += $child.toString().trim(); - } - }); - } else { - // http://rail.ally.net.cn/html/2022/InviteTen_0407/4686.html - description = $('div.content div').first().html(); - } + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const response = await got(item.link); + const $ = cheerio.load(response.data); + // fix weird format + let description = ''; + const content = $('div.content_all'); + if (content.length) { + content + .eq(content.length - 1) // some pages have "summary" + .contents() + .each((_, child) => { + const $child = $(child); + let innerHtml; + if (child.name === 'div') { + innerHtml = $child.html(); + innerHtml = innerHtml && innerHtml.trim(); + description += !innerHtml || innerHtml === ' ' ? (description ? '
' : '') : innerHtml; + } else { + // bare text node or something else + description += $child.toString().trim(); + } + }); + } else { + // http://rail.ally.net.cn/html/2022/InviteTen_0407/4686.html + description = $('div.content div').first().html(); + } - description = description.replace(/\s*
\s*$/, ''); // trim
at the end - const info = $('.content > em span'); - return { - title: $('.content > h2').text() || item.title, - description, - // pubDate: timezone(parseDate(info.eq(0).text()), 8), - pubDate: item.pubDate, - author: info - .eq(1) - .text() - .replace(/^来源:/, ''), - link: item.link, - }; - }) + description = description.replace(/\s*
\s*$/, ''); // trim
at the end + const info = $('.content > em span'); + return { + title: $('.content > h2').text() || item.title, + description, + // pubDate: timezone(parseDate(info.eq(0).text()), 8), + pubDate: item.pubDate, + author: info + .eq(1) + .text() + .replace(/^来源:/, ''), + link: item.link, + }; + }) ) ); diff --git a/lib/v2/bilibili/video-all.js b/lib/v2/bilibili/video-all.js index edf58b3faa..0e4b396dc6 100644 --- a/lib/v2/bilibili/video-all.js +++ b/lib/v2/bilibili/video-all.js @@ -35,7 +35,7 @@ module.exports = async (ctx) => { }, }); const params = utils.addVerifyInfo(`mid=${uid}&ps=30&tid=0&pn=${pageId}&keyword=&order=pubdate&order_avoided=true`, verifyString); - return await got(`https://api.bilibili.com/x/space/wbi/arc/search?${params}`, { + return got(`https://api.bilibili.com/x/space/wbi/arc/search?${params}`, { headers: { Referer: `https://space.bilibili.com/${uid}/video?tid=0&page=${pageId}&keyword=&order=pubdate`, Cookie: cookie, diff --git a/lib/v2/bioone/journal.js b/lib/v2/bioone/journal.js index 6e2a5cad1b..0619e7675b 100644 --- a/lib/v2/bioone/journal.js +++ b/lib/v2/bioone/journal.js @@ -27,28 +27,27 @@ module.exports = async (ctx) => { }); items = await Promise.all( - items.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got(item.link, { - https: { - rejectUnauthorized: false, - }, - }); + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got(item.link, { + https: { + rejectUnauthorized: false, + }, + }); - const content = cheerio.load(detailResponse.data); + const content = cheerio.load(detailResponse.data); - content('.ProceedingsArticleOpenAccessPanel').remove(); - content('#divNotSignedSection, #rightRail').remove(); + content('.ProceedingsArticleOpenAccessPanel').remove(); + content('#divNotSignedSection, #rightRail').remove(); - item.description = content('.panel-body').html(); - item.title = content('meta[name="dc.Title"]').attr('content'); - item.author = content('meta[name="dc.Creator"]').attr('content'); - item.doi = content('meta[name="dc.Identifier"]').attr('content'); - item.pubDate = parseDate(content('meta[name="dc.Date"]').attr('content')); + item.description = content('.panel-body').html(); + item.title = content('meta[name="dc.Title"]').attr('content'); + item.author = content('meta[name="dc.Creator"]').attr('content'); + item.doi = content('meta[name="dc.Identifier"]').attr('content'); + item.pubDate = parseDate(content('meta[name="dc.Date"]').attr('content')); - return item; - }) + return item; + }) ) ); diff --git a/lib/v2/bjfu/it/utils.js b/lib/v2/bjfu/it/utils.js index 45938bc0cd..ded31bf02a 100644 --- a/lib/v2/bjfu/it/utils.js +++ b/lib/v2/bjfu/it/utils.js @@ -32,9 +32,9 @@ async function load(link) { return { description, pubDate }; } -const ProcessFeed = async (base, list, caches) => +const ProcessFeed = (base, list, caches) => // 使用 Promise.all() 进行 async 并发 - await Promise.all( + Promise.all( // 遍历每一篇文章 list.map(async (item) => { const $ = cheerio.load(item); @@ -53,7 +53,7 @@ const ProcessFeed = async (base, list, caches) => // 使用tryGet方法从缓存获取内容。 // 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。 - const other = await caches.tryGet(itemUrl, async () => await load(itemUrl)); + const other = await caches.tryGet(itemUrl, () => load(itemUrl)); // 合并解析后的结果集作为该篇文章最终的输出结果 return { ...single, ...other }; diff --git a/lib/v2/bloomberg/utils.js b/lib/v2/bloomberg/utils.js index 40f2874bb3..48f592c8e0 100644 --- a/lib/v2/bloomberg/utils.js +++ b/lib/v2/bloomberg/utils.js @@ -73,8 +73,8 @@ const parseNewsList = async (url, ctx) => { }); }; -const parseArticle = async (item, ctx) => - await ctx.cache.tryGet(item.link, async () => { +const parseArticle = (item, ctx) => + ctx.cache.tryGet(item.link, async () => { const group = regex .map((r) => r.exec(item.link)) .filter((e) => e && e.groups) @@ -116,15 +116,15 @@ const parseArticle = async (item, ctx) => switch (page) { case 'audio': - return await parseAudioPage(res, api, item); + return parseAudioPage(res, api, item); case 'videos': - return await parseVideoPage(res, api, item); + return parseVideoPage(res, api, item); case 'photo-essays': - return await parsePhotoEssaysPage(res, api, item); + return parsePhotoEssaysPage(res, api, item); case 'features/': // single features page - return await parseFeaturePage(res, api, item); + return parseFeaturePage(res, api, item); default: - return await parseOtherPage(res, api, item); + return parseOtherPage(res, api, item); } } } @@ -199,7 +199,7 @@ const parseFeaturePage = async (res, api, item) => { const article_json = JSON.parse(JSON.parse(json)); const meta = article_json.meta; - const desc = article_json.blocks.map(async (b) => { + const desc = article_json.blocks.map((b) => { if (b.type === 'Paragraph') { return b.props.text.html; } @@ -208,7 +208,7 @@ const parseFeaturePage = async (res, api, item) => { return art(path.join(__dirname, 'templates/image_figure.art'), image); } if (b.type === 'Lede') { - return await processLedeMedia(b); + return processLedeMedia(b); } return ''; }); diff --git a/lib/v2/caareviews/utils.js b/lib/v2/caareviews/utils.js index 2fd12d524d..23b544f585 100644 --- a/lib/v2/caareviews/utils.js +++ b/lib/v2/caareviews/utils.js @@ -20,8 +20,8 @@ const getList = async (url) => { return list; }; -const getItems = async (ctx, list) => - await Promise.all( +const getItems = (ctx, list) => + Promise.all( list.map((item) => ctx.cache.tryGet(item.link, async () => { const detailResponse = await got(item.link); diff --git a/lib/v2/cctv/lm.js b/lib/v2/cctv/lm.js index 94172546d9..b0d4227338 100644 --- a/lib/v2/cctv/lm.js +++ b/lib/v2/cctv/lm.js @@ -38,34 +38,33 @@ module.exports = async (ctx) => { })); const items = await Promise.all( - list.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const data = detailResponse.data; + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const data = detailResponse.data; - item.description += `
`; + item.description += `
`; - for (const c of data.video.chapters) { + for (const c of data.video.chapters) { + item.description += `
`; + } + + for (let i = 2; data.video[`chapters${i}`]; i++) { + for (const c of data.video[`chapters${i}`]) { item.description += `
`; } + } - for (let i = 2; data.video[`chapters${i}`]; i++) { - for (const c of data.video[`chapters${i}`]) { - item.description += `
`; - } - } + item.link = item.url; - item.link = item.url; + delete item.url; + delete item.image; - delete item.url; - delete item.image; - - return item; - }) + return item; + }) ) ); diff --git a/lib/v2/chinacef/experts.js b/lib/v2/chinacef/experts.js index eb48ecdbb9..a578b3c645 100644 --- a/lib/v2/chinacef/experts.js +++ b/lib/v2/chinacef/experts.js @@ -18,7 +18,7 @@ module.exports = async (ctx) => { .map(async (index, item) => { item = $(item); const itemLink = utils.siteLink + item.find('h2 > a').attr('href'); - const detail = await ctx.cache.tryGet(itemLink, async () => await utils.getArticleDetail(itemLink)); + const detail = await ctx.cache.tryGet(itemLink, () => utils.getArticleDetail(itemLink)); return { title: detail.title, diff --git a/lib/v2/chinacef/hot.js b/lib/v2/chinacef/hot.js index 1637b94970..24717b2c47 100644 --- a/lib/v2/chinacef/hot.js +++ b/lib/v2/chinacef/hot.js @@ -17,7 +17,7 @@ module.exports = async (ctx) => { .map(async (index, item) => { item = $(item); const itemLink = utils.siteLink + item.find('li a').attr('href'); - const detail = await ctx.cache.tryGet(itemLink, async () => await utils.getArticleDetail(itemLink)); + const detail = await ctx.cache.tryGet(itemLink, () => utils.getArticleDetail(itemLink)); return { title: detail.title, diff --git a/lib/v2/chinacef/index.js b/lib/v2/chinacef/index.js index 18725a549a..93ecc13430 100644 --- a/lib/v2/chinacef/index.js +++ b/lib/v2/chinacef/index.js @@ -18,7 +18,7 @@ module.exports = async (ctx) => { articlesLinkList.map(async (item) => { const articlesLink = utils.siteLink + item; - const detail = await ctx.cache.tryGet(articlesLink, async () => await utils.getArticleDetail(articlesLink)); + const detail = await ctx.cache.tryGet(articlesLink, () => utils.getArticleDetail(articlesLink)); const element = { title: detail.title, diff --git a/lib/v2/chinafactcheck/index.js b/lib/v2/chinafactcheck/index.js index 86ccfa2627..e7998d5c41 100644 --- a/lib/v2/chinafactcheck/index.js +++ b/lib/v2/chinafactcheck/index.js @@ -17,7 +17,7 @@ module.exports = async (ctx) => { articlesLinkList.map(async (item) => { const articlesLink = item; - const detail = await ctx.cache.tryGet(articlesLink, async () => await utils.getArticleDetail(articlesLink)); + const detail = await ctx.cache.tryGet(articlesLink, () => utils.getArticleDetail(articlesLink)); const element = { title: detail.title, diff --git a/lib/v2/chinathinktanks/viewpoint.js b/lib/v2/chinathinktanks/viewpoint.js index 089fb73581..b9ff1674ef 100644 --- a/lib/v2/chinathinktanks/viewpoint.js +++ b/lib/v2/chinathinktanks/viewpoint.js @@ -28,20 +28,19 @@ module.exports = async (ctx) => { }); items = await Promise.all( - items.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const response = await got({ - url: item.link, - cookieJar, - }); - const $ = cheerio.load(response.data); - const content = $('#art'); - item.description = content.html(); - item.pubDate = item.pubDate.includes('-') ? timezone(parseDate(item.pubDate, 'YYYY-MM-DD'), +8) : parseRelativeDate(item.pubDate); + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const response = await got({ + url: item.link, + cookieJar, + }); + const $ = cheerio.load(response.data); + const content = $('#art'); + item.description = content.html(); + item.pubDate = item.pubDate.includes('-') ? timezone(parseDate(item.pubDate, 'YYYY-MM-DD'), +8) : parseRelativeDate(item.pubDate); - return item; - }) + return item; + }) ) ); diff --git a/lib/v2/ciidbnu/index.js b/lib/v2/ciidbnu/index.js index e1481c295c..87f26071dc 100644 --- a/lib/v2/ciidbnu/index.js +++ b/lib/v2/ciidbnu/index.js @@ -28,25 +28,24 @@ module.exports = async (ctx) => { .get(); const items = await Promise.all( - list.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - responseType: 'buffer', - }); - const content = cheerio.load(iconv.decode(detailResponse.data, 'gbk')); + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + responseType: 'buffer', + }); + const content = cheerio.load(iconv.decode(detailResponse.data, 'gbk')); - item.description = content('#text').html(); - item.pubDate = timezone(parseDate(content('.t8').eq(0).text(), 'YYYY/M/D H:mm:ss'), +8); + item.description = content('#text').html(); + item.pubDate = timezone(parseDate(content('.t8').eq(0).text(), 'YYYY/M/D H:mm:ss'), +8); - content('.t14').remove(); + content('.t14').remove(); - item.author = content('#author').text(); + item.author = content('#author').text(); - return item; - }) + return item; + }) ) ); diff --git a/lib/v2/dcard/section.js b/lib/v2/dcard/section.js index 8fa483fd1b..c5d5ef8c6f 100644 --- a/lib/v2/dcard/section.js +++ b/lib/v2/dcard/section.js @@ -38,7 +38,7 @@ module.exports = async (ctx) => { await page.goto(`${api}&limit=100`); await page.waitForSelector('body > pre'); const response = await page.evaluate(() => document.querySelector('body > pre').innerText); - const cookies = await ctx.cache.tryGet('dcard:cookies', async () => await page.cookies(), 3600, false); + const cookies = await ctx.cache.tryGet('dcard:cookies', () => page.cookies(), 3600, false); await page.close(); const data = JSON.parse(response); diff --git a/lib/v2/disinformationindex/blog.js b/lib/v2/disinformationindex/blog.js index e62568efbe..69cc7ae8e7 100644 --- a/lib/v2/disinformationindex/blog.js +++ b/lib/v2/disinformationindex/blog.js @@ -23,21 +23,20 @@ module.exports = async (ctx) => { .get(); const items = await Promise.all( - list.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = cheerio.load(detailResponse.data); + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); - item.author = content('.meta-author').text(); - item.description = content('.entry-content').html(); - item.pubDate = parseDate(content('.meta-date').text(), 'MMMM D, YYYY'); + item.author = content('.meta-author').text(); + item.description = content('.entry-content').html(); + item.pubDate = parseDate(content('.meta-date').text(), 'MMMM D, YYYY'); - return item; - }) + return item; + }) ) ); diff --git a/lib/v2/dtcj/datainsight.js b/lib/v2/dtcj/datainsight.js index 5824508589..926f3490f3 100644 --- a/lib/v2/dtcj/datainsight.js +++ b/lib/v2/dtcj/datainsight.js @@ -28,20 +28,19 @@ module.exports = async (ctx) => { .get(); const items = await Promise.all( - list.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = cheerio.load(detailResponse.data); + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); - item.description = content('.content-3mNFyi').html(); - item.pubDate = parseDate(detailResponse.data.match(/"date":"(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}\+\d{2}:\d{2})","thumbnail_url":/)[1]); + item.description = content('.content-3mNFyi').html(); + item.pubDate = parseDate(detailResponse.data.match(/"date":"(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}\+\d{2}:\d{2})","thumbnail_url":/)[1]); - return item; - }) + return item; + }) ) ); diff --git a/lib/v2/eastday/24.js b/lib/v2/eastday/24.js index f13412b5c6..509d8d30fa 100644 --- a/lib/v2/eastday/24.js +++ b/lib/v2/eastday/24.js @@ -59,21 +59,20 @@ module.exports = async (ctx) => { links.push(item.link.replace(/\.html/, `-${i}.html`)); } - links.forEach( - async (link) => - await ctx.cache.tryGet(link, async () => { - const pageResponse = await got({ - method: 'get', - url: link, - }); - const subContent = cheerio.load(pageResponse.data); + links.forEach((link) => + ctx.cache.tryGet(link, async () => { + const pageResponse = await got({ + method: 'get', + url: link, + }); + const subContent = cheerio.load(pageResponse.data); - subContent('img').each(function () { - subContent(this).attr('src', subContent(this).attr('data-url')); - }); + subContent('img').each(function () { + subContent(this).attr('src', subContent(this).attr('data-url')); + }); - item.description += subContent('#J-contain_detail_cnt').html(); - }) + item.description += subContent('#J-contain_detail_cnt').html(); + }) ); } diff --git a/lib/v2/economist/full.js b/lib/v2/economist/full.js index fb08c4d3f7..4ad4262a88 100644 --- a/lib/v2/economist/full.js +++ b/lib/v2/economist/full.js @@ -2,8 +2,8 @@ const parser = require('@/utils/rss-parser'); const got = require('@/utils/got'); const cheerio = require('cheerio'); -const getArticleDetail = async (link, ctx) => - await ctx.cache.tryGet(link, async () => { +const getArticleDetail = (link, ctx) => + ctx.cache.tryGet(link, async () => { const response = await got(link); const $ = cheerio.load(response.data); $('div.article-audio-player__center-tooltip').remove(); diff --git a/lib/v2/flyert/utils.js b/lib/v2/flyert/utils.js index d5ba850616..109febfef9 100644 --- a/lib/v2/flyert/utils.js +++ b/lib/v2/flyert/utils.js @@ -33,10 +33,10 @@ async function load(link) { return { description }; } -const ProcessFeed = async (list, caches) => { +const ProcessFeed = (list, caches) => { const host = 'https://www.flyert.com'; - return await Promise.all( + return Promise.all( list.map(async (item) => { const $ = cheerio.load(item); @@ -54,7 +54,7 @@ const ProcessFeed = async (list, caches) => { // 使用tryGet方法从缓存获取内容。 // 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。 - const other = await caches.tryGet(itemUrl, async () => await load(itemUrl)); + const other = await caches.tryGet(itemUrl, () => load(itemUrl)); // 合并解析后的结果集作为该篇文章最终的输出结果 return Promise.resolve(Object.assign({}, single, other)); diff --git a/lib/v2/gocn/topics.js b/lib/v2/gocn/topics.js index b880bcbf1e..713e7b2d28 100644 --- a/lib/v2/gocn/topics.js +++ b/lib/v2/gocn/topics.js @@ -18,6 +18,6 @@ module.exports = async (ctx) => { title: `GoCN社区-文章`, link: base_url, description: `获取GoCN站点最新文章`, - item: await Promise.all(list.map(async (item) => await ctx.cache.tryGet(`${base_url}/${item.guid}`, () => util.getFeedItem(item)))), + item: await Promise.all(list.map((item) => ctx.cache.tryGet(`${base_url}/${item.guid}`, () => util.getFeedItem(item)))), }; }; diff --git a/lib/v2/google/sitesRecentChanges.js b/lib/v2/google/sitesRecentChanges.js index 53db7cfb16..de5d308d63 100644 --- a/lib/v2/google/sitesRecentChanges.js +++ b/lib/v2/google/sitesRecentChanges.js @@ -28,19 +28,18 @@ module.exports = async (ctx) => { }); items = await Promise.all( - items.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = cheerio.load(detailResponse.data); + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); - item.description = content('#sites-canvas').html(); + item.description = content('#sites-canvas').html(); - return item; - }) + return item; + }) ) ); diff --git a/lib/v2/gov/ccdi/utils.js b/lib/v2/gov/ccdi/utils.js index d48af9deac..03944e7174 100644 --- a/lib/v2/gov/ccdi/utils.js +++ b/lib/v2/gov/ccdi/utils.js @@ -64,7 +64,7 @@ const changeTrCookie = async () => { const parseArticle = async (item, ctx) => { await changeTrCookie(); - return await ctx.cache.tryGet(item.link, async () => { + return ctx.cache.tryGet(item.link, async () => { const response = await got(item.link, { cookieJar }); const data = response.data; await parseCookie(data); diff --git a/lib/v2/gov/pbc/utils.js b/lib/v2/gov/pbc/utils.js index 8478f39121..bd06f37780 100644 --- a/lib/v2/gov/pbc/utils.js +++ b/lib/v2/gov/pbc/utils.js @@ -1,8 +1,8 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); -const processItems = async (list, ctx) => - await Promise.all( +const processItems = (list, ctx) => + Promise.all( list.map((item) => ctx.cache.tryGet(item.link, async () => { const detailResponse = await got.post(item.link); diff --git a/lib/v2/gov/sichuan/deyang/govpulicinfo.js b/lib/v2/gov/sichuan/deyang/govpulicinfo.js index 09a52b6dc4..ae0126e0a9 100644 --- a/lib/v2/gov/sichuan/deyang/govpulicinfo.js +++ b/lib/v2/gov/sichuan/deyang/govpulicinfo.js @@ -45,8 +45,8 @@ const getInfoUrlList = async (countyName) => { }; // 获取信息正文内容 -const getInfoContent = async (ctx, url, countyName) => - await ctx.cache.tryGet(url, async () => { +const getInfoContent = (ctx, url, countyName) => + ctx.cache.tryGet(url, async () => { let response; try { response = await got(url); @@ -80,7 +80,7 @@ const getInfoContent = async (ctx, url, countyName) => module.exports = async (ctx) => { const countyName = ctx.params.countyName; const infoUrlList = await getInfoUrlList(countyName); - const items = await Promise.all(infoUrlList.map(async (item) => await getInfoContent(ctx, item, countyName))); + const items = await Promise.all(infoUrlList.map((item) => getInfoContent(ctx, item, countyName))); ctx.state.data = { title: `政府公开信息 - ${countyName}`, diff --git a/lib/v2/gov/stats/utils.js b/lib/v2/gov/stats/utils.js index ce2a459d4a..ef47ac6216 100644 --- a/lib/v2/gov/stats/utils.js +++ b/lib/v2/gov/stats/utils.js @@ -26,8 +26,8 @@ const parseContList = async (url, selector, ctx) => { return { list, title }; }; -const parseXilan = async (item, ctx) => - await ctx.cache.tryGet(item.link, async () => { +const parseXilan = (item, ctx) => + ctx.cache.tryGet(item.link, async () => { const response = await got(item.link); const $ = cheerio.load(response.data); const title = $('.xilan_titf').text(); diff --git a/lib/v2/gzh360/universal.js b/lib/v2/gzh360/universal.js index c8bd7998b6..c24f51f3dc 100644 --- a/lib/v2/gzh360/universal.js +++ b/lib/v2/gzh360/universal.js @@ -4,8 +4,8 @@ const { parseDate } = require('@/utils/parse-date'); const { finishArticleItem } = require('./utils'); const config = require('@/config').value; -const getInitEntry = async (url) => - await got(url) +const getInitEntry = (url) => + got(url) .then((_r) => _r.data) .catch((err) => { if (err.response.statusCode === 404) { @@ -18,7 +18,7 @@ module.exports = async (ctx, path, id, titleHeader = '', custom_title = null, sk const rootUrl = 'http://web.gzh360.com'; const currentUrl = `${rootUrl}/${id ? `${path}?id=${id}` : ''}`; - const respData = cacheInitEntry ? await ctx.cache.tryGet(currentUrl, async () => await getInitEntry(currentUrl), config.cache.routeExpire, false) : await getInitEntry(currentUrl); + const respData = cacheInitEntry ? await ctx.cache.tryGet(currentUrl, () => getInitEntry(currentUrl), config.cache.routeExpire, false) : await getInitEntry(currentUrl); const $ = cheerio.load(respData); const title = id ? $('head > title').text().split(' - ', 1)[0] : '首页'; diff --git a/lib/v2/gzh360/utils.js b/lib/v2/gzh360/utils.js index f4e35c5d30..a188d860da 100644 --- a/lib/v2/gzh360/utils.js +++ b/lib/v2/gzh360/utils.js @@ -36,8 +36,8 @@ const finishArticleItem = async (ctx, item, skipAuthor = false) => { // we can't cache the item instead of the webpage because we need to retry when the last request failed const article = await ctx.cache.tryGet( item.link, - async () => - await got(item.link) + () => + got(item.link) .then((_r) => _r.data) .catch(() => null) // it is safe do that in tryGet because a false value always lead to a cache miss ); diff --git a/lib/v2/hk01/utils.js b/lib/v2/hk01/utils.js index 5023369fb1..12043de1de 100644 --- a/lib/v2/hk01/utils.js +++ b/lib/v2/hk01/utils.js @@ -9,8 +9,8 @@ const apiRootUrl = 'https://web-data.api.hk01.com'; module.exports = { rootUrl, apiRootUrl, - ProcessItems: async (items, limit, tryGet) => - await Promise.all( + ProcessItems: (items, limit, tryGet) => + Promise.all( items .filter((item) => item.type !== 2) .slice(0, limit ? parseInt(limit) : 50) diff --git a/lib/v2/njnu/ceai/utils.js b/lib/v2/njnu/ceai/utils.js index dfae970257..1a9f2dd735 100644 --- a/lib/v2/njnu/ceai/utils.js +++ b/lib/v2/njnu/ceai/utils.js @@ -23,8 +23,8 @@ async function load(link) { return { description, pubDate }; } -const ProcessFeed = async (list, caches) => - await Promise.all( +const ProcessFeed = (list, caches) => + Promise.all( // 遍历每一篇文章 list.map(async (item) => { const $ = cheerio.load(item); @@ -43,7 +43,7 @@ const ProcessFeed = async (list, caches) => // 使用tryGet方法从缓存获取内容。 // 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。 - const other = await caches.tryGet(itemUrl, async () => await load(itemUrl)); + const other = await caches.tryGet(itemUrl, () => load(itemUrl)); // 合并解析后的结果集作为该篇文章最终的输出结果 return { ...single, ...other }; diff --git a/lib/v2/njnu/jwc/utils.js b/lib/v2/njnu/jwc/utils.js index cf6713678f..a29366436f 100644 --- a/lib/v2/njnu/jwc/utils.js +++ b/lib/v2/njnu/jwc/utils.js @@ -23,11 +23,11 @@ async function load(link) { return { description, pubDate }; } -const ProcessFeed = async (list, caches) => { +const ProcessFeed = (list, caches) => { const host = 'http://jwc.njnu.edu.cn/'; // 使用 Promise.all() 进行 async 并发 - return await Promise.all( + return Promise.all( // 遍历每一篇文章 list.map(async (item) => { const $ = cheerio.load(item); @@ -46,7 +46,7 @@ const ProcessFeed = async (list, caches) => { // 使用tryGet方法从缓存获取内容。 // 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。 - const other = await caches.tryGet(itemUrl, async () => await load(itemUrl)); + const other = await caches.tryGet(itemUrl, () => load(itemUrl)); // 合并解析后的结果集作为该篇文章最终的输出结果 return { ...single, ...other }; diff --git a/lib/v2/nua/utils.js b/lib/v2/nua/utils.js index 47ccfe8fd8..ea2cb6706c 100644 --- a/lib/v2/nua/utils.js +++ b/lib/v2/nua/utils.js @@ -45,8 +45,8 @@ async function ProcessList(newsUrl, baseUrl, listName, listDate, webPageName) { return [items, pageName]; } -const ProcessFeed = async (items, artiContent, ctx) => - await Promise.all( +const ProcessFeed = (items, artiContent, ctx) => + Promise.all( items.map((item) => ctx.cache.tryGet(item.link, async () => { switch (item.type) { diff --git a/lib/v2/odaily/activity.js b/lib/v2/odaily/activity.js index c7128381bf..e8e7a3b8c4 100644 --- a/lib/v2/odaily/activity.js +++ b/lib/v2/odaily/activity.js @@ -19,24 +19,23 @@ module.exports = async (ctx) => { })); items = await Promise.all( - items.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); - const content = cheerio.load(detailResponse.data.match(/"content":"(.*)"}},"secondaryList":/)[1]); + const content = cheerio.load(detailResponse.data.match(/"content":"(.*)"}},"secondaryList":/)[1]); - content('img').each(function () { - content(this).attr('src', content(this).attr('src').replace(/\\"/g, '')); - }); + content('img').each(function () { + content(this).attr('src', content(this).attr('src').replace(/\\"/g, '')); + }); - item.description = content.html(); + item.description = content.html(); - return item; - }) + return item; + }) ) ); diff --git a/lib/v2/odaily/user.js b/lib/v2/odaily/user.js index 04117cced8..f7a8901277 100644 --- a/lib/v2/odaily/user.js +++ b/lib/v2/odaily/user.js @@ -24,25 +24,24 @@ module.exports = async (ctx) => { })); items = await Promise.all( - items.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); - const content = cheerio.load(detailResponse.data.match(/"content":"(.*)","extraction_tags":/)[1]); + const content = cheerio.load(detailResponse.data.match(/"content":"(.*)","extraction_tags":/)[1]); - content('img').each(function () { - content(this).attr('src', content(this).attr('src').replace(/\\"/g, '')); - }); + content('img').each(function () { + content(this).attr('src', content(this).attr('src').replace(/\\"/g, '')); + }); - item.description = content.html(); - item.author = author = detailResponse.data.match(/"name":"(.*)","role_id/)[1]; + item.description = content.html(); + item.author = author = detailResponse.data.match(/"name":"(.*)","role_id/)[1]; - return item; - }) + return item; + }) ) ); diff --git a/lib/v2/oilchem/index.js b/lib/v2/oilchem/index.js index e884a0ea0c..4de1945c1d 100644 --- a/lib/v2/oilchem/index.js +++ b/lib/v2/oilchem/index.js @@ -33,29 +33,28 @@ module.exports = async (ctx) => { .get(); const items = await Promise.all( - list.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = cheerio.load(detailResponse.data); + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); - item.description = content('#content').html(); - item.pubDate = timezone( - parseDate( - content('.xq-head') - .find('span') - .text() - .match(/发布时间:\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}/)[0], - 'YYYY-MM-DD HH:mm' - ), - +8 - ); + item.description = content('#content').html(); + item.pubDate = timezone( + parseDate( + content('.xq-head') + .find('span') + .text() + .match(/发布时间:\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}/)[0], + 'YYYY-MM-DD HH:mm' + ), + +8 + ); - return item; - }) + return item; + }) ) ); diff --git a/lib/v2/sdu/extractor/index.js b/lib/v2/sdu/extractor/index.js index 97cc111781..13861ac1bc 100644 --- a/lib/v2/sdu/extractor/index.js +++ b/lib/v2/sdu/extractor/index.js @@ -1,15 +1,15 @@ -module.exports = async (link, ctx) => { +module.exports = (link, ctx) => { if (link.startsWith('https://xinwen.wh.sdu.edu.cn/')) { - return await require('./wh/news')(link, ctx); + return require('./wh/news')(link, ctx); } if (link.startsWith('https://www.view.sdu.edu.cn/')) { - return await require('./view')(link, ctx); + return require('./view')(link, ctx); } if (link.startsWith('https://www.sdrj.sdu.edu.cn/')) { - return await require('./sdrj')(link, ctx); + return require('./sdrj')(link, ctx); } if (link.startsWith('https://jwc.wh.sdu.edu.cn/')) { - return await require('./wh/jwc')(link, ctx); + return require('./wh/jwc')(link, ctx); } return {}; }; diff --git a/lib/v2/sdu/extractor/sdrj.js b/lib/v2/sdu/extractor/sdrj.js index 0734841131..49be530f8c 100644 --- a/lib/v2/sdu/extractor/sdrj.js +++ b/lib/v2/sdu/extractor/sdrj.js @@ -3,8 +3,8 @@ const cheerio = require('cheerio'); const { parseDate } = require('@/utils/parse-date'); const timezone = require('@/utils/timezone'); -module.exports = async (link, ctx) => - await ctx.cache.tryGet(link, async () => { +module.exports = (link, ctx) => + ctx.cache.tryGet(link, async () => { let content, author, exactDate; try { const result = await got(link); diff --git a/lib/v2/sdu/extractor/view.js b/lib/v2/sdu/extractor/view.js index 35647e247b..f28e94a50a 100644 --- a/lib/v2/sdu/extractor/view.js +++ b/lib/v2/sdu/extractor/view.js @@ -3,8 +3,8 @@ const cheerio = require('cheerio'); const { parseDate } = require('@/utils/parse-date'); const timezone = require('@/utils/timezone'); -module.exports = async (link, ctx) => - await ctx.cache.tryGet(link, async () => { +module.exports = (link, ctx) => + ctx.cache.tryGet(link, async () => { let content, author, exactDate; try { const result = await got(link); diff --git a/lib/v2/sdu/extractor/wh/jwc.js b/lib/v2/sdu/extractor/wh/jwc.js index 18e06ace2d..fd9ad235b0 100644 --- a/lib/v2/sdu/extractor/wh/jwc.js +++ b/lib/v2/sdu/extractor/wh/jwc.js @@ -3,8 +3,8 @@ const cheerio = require('cheerio'); const { parseDate } = require('@/utils/parse-date'); const timezone = require('@/utils/timezone'); -module.exports = async (link, ctx) => - await ctx.cache.tryGet(link, async () => { +module.exports = (link, ctx) => + ctx.cache.tryGet(link, async () => { let content, exactDate; try { const result = await got(link); diff --git a/lib/v2/sdu/extractor/wh/news.js b/lib/v2/sdu/extractor/wh/news.js index d7e6041688..18ed5f9915 100644 --- a/lib/v2/sdu/extractor/wh/news.js +++ b/lib/v2/sdu/extractor/wh/news.js @@ -3,8 +3,8 @@ const cheerio = require('cheerio'); const { parseDate } = require('@/utils/parse-date'); const timezone = require('@/utils/timezone'); -module.exports = async (link, ctx) => - await ctx.cache.tryGet(link, async () => { +module.exports = (link, ctx) => + ctx.cache.tryGet(link, async () => { let content, author, exactDate; try { const result = await got(link); diff --git a/lib/v2/sdu/wh/jwc.js b/lib/v2/sdu/wh/jwc.js index be17c02960..a6047a4e8a 100644 --- a/lib/v2/sdu/wh/jwc.js +++ b/lib/v2/sdu/wh/jwc.js @@ -21,7 +21,7 @@ module.exports = async (ctx) => { const href = anchor.attr('href'); const link = href.startsWith('http') ? href : baseUrl + href; const title = item.text(); - const { description, author: exactAuthor, exactDate } = await ctx.cache.tryGet(link, async () => await extractor(link, ctx)); + const { description, author: exactAuthor, exactDate } = await ctx.cache.tryGet(link, () => extractor(link, ctx)); const author = exactAuthor ?? '教务处'; const pubDate = exactDate ?? timezone(parseDate(dateText.slice(1, dateText.length - 1), 'YYYY-MM-DD'), +8); return { diff --git a/lib/v2/sdu/wh/news.js b/lib/v2/sdu/wh/news.js index b1511f5165..1abd255945 100644 --- a/lib/v2/sdu/wh/news.js +++ b/lib/v2/sdu/wh/news.js @@ -17,7 +17,7 @@ module.exports = async (ctx) => { const title = anchor.attr('title'); const href = anchor.attr('href'); const link = href.startsWith('http') ? href : baseUrl + href; - const { description, author, exactDate } = await ctx.cache.tryGet(link, async () => await extractor(link, ctx)); + const { description, author, exactDate } = await ctx.cache.tryGet(link, () => extractor(link, ctx)); const span = item.find('span'); const pubDate = exactDate ?? parseDate(span.text(), 'YYYY/MM/DD'); return { diff --git a/lib/v2/shmeea/self-study.js b/lib/v2/shmeea/self-study.js index ec1118b867..ffb76eaedf 100644 --- a/lib/v2/shmeea/self-study.js +++ b/lib/v2/shmeea/self-study.js @@ -3,9 +3,9 @@ const cheerio = require('cheerio'); const { parseDate } = require('@/utils/parse-date'); const timezone = require('@/utils/timezone'); -async function load_detail(list, cache) { - return await Promise.all( - list.map(async (item) => { +function load_detail(list, cache) { + return Promise.all( + list.map((item) => { const notice_item = cheerio.load(item); const href = notice_item('a').attr('href'); const url = 'http://www.shmeea.edu.cn' + href; @@ -16,7 +16,7 @@ async function load_detail(list, cache) { link: href, }; } - return await cache.tryGet(url, async () => { + return cache.tryGet(url, async () => { const detail_response = await got({ method: 'get', url, diff --git a/lib/v2/sicau/dky.js b/lib/v2/sicau/dky.js index 47881344ac..23a4377f45 100644 --- a/lib/v2/sicau/dky.js +++ b/lib/v2/sicau/dky.js @@ -29,19 +29,18 @@ module.exports = async (ctx) => { .get(); const items = await Promise.all( - list.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = cheerio.load(detailResponse.data); + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); - item.description = content('.v_news_content').html(); + item.description = content('.v_news_content').html(); - return item; - }) + return item; + }) ) ); diff --git a/lib/v2/sicau/yan.js b/lib/v2/sicau/yan.js index 11b81fb98c..1386269064 100644 --- a/lib/v2/sicau/yan.js +++ b/lib/v2/sicau/yan.js @@ -28,20 +28,19 @@ module.exports = async (ctx) => { .get(); const items = await Promise.all( - list.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = cheerio.load(detailResponse.data); + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); - item.description = content('.v_news_content').html(); - item.pubDate = timezone(parseDate(detailResponse.data.match(/发布时间: (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})/)[1], 'YYYY-MM-DD HH:mm:ss'), +8); + item.description = content('.v_news_content').html(); + item.pubDate = timezone(parseDate(detailResponse.data.match(/发布时间: (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})/)[1], 'YYYY-MM-DD HH:mm:ss'), +8); - return item; - }) + return item; + }) ) ); diff --git a/lib/v2/thepaper/utils.js b/lib/v2/thepaper/utils.js index 71737e82d7..654ed586f3 100644 --- a/lib/v2/thepaper/utils.js +++ b/lib/v2/thepaper/utils.js @@ -17,13 +17,13 @@ const defaultRssItem = (item) => ({ }); module.exports = { - ProcessItem: async (item, ctx) => { + ProcessItem: (item, ctx) => { if (item.link) { // external link return defaultRssItem(item); } const itemUrl = `https://m.thepaper.cn/detail/${item.contId}`; - return await ctx.cache.tryGet(itemUrl, async () => { + return ctx.cache.tryGet(itemUrl, async () => { const res = await got(itemUrl); const data = JSON.parse(cheerio.load(res.data)('#__NEXT_DATA__').html()); const detailData = data.props.pageProps.detailData; diff --git a/lib/v2/twitter/web-api/twitter-api.js b/lib/v2/twitter/web-api/twitter-api.js index 1409d4e35d..2ff909432a 100644 --- a/lib/v2/twitter/web-api/twitter-api.js +++ b/lib/v2/twitter/web-api/twitter-api.js @@ -199,13 +199,13 @@ const cacheTryGet = async (cache, screenName, params, func) => { const id = await getUserID(cache, screenName); const funcName = func.name; const paramsString = JSON.stringify(params); - return await cache.tryGet(`twitter:${id}:${funcName}:${paramsString}`, async () => await func(id, params), config.cache.routeExpire, false); + return cache.tryGet(`twitter:${id}:${funcName}:${paramsString}`, () => func(id, params), config.cache.routeExpire, false); }; -const getUserTweets = async (cache, screenName, params = {}) => await cacheTryGet(cache, screenName, params, getUserTweetsByID); -const getUserTweetsAndReplies = async (cache, screenName, params = {}) => await cacheTryGet(cache, screenName, params, getUserTweetsAndRepliesByID); -const getUserMedia = async (cache, screenName, params = {}) => await cacheTryGet(cache, screenName, params, getUserMediaByID); -const getUserLikes = async (cache, screenName, params = {}) => await cacheTryGet(cache, screenName, params, getUserLikesByID); +const getUserTweets = (cache, screenName, params = {}) => cacheTryGet(cache, screenName, params, getUserTweetsByID); +const getUserTweetsAndReplies = (cache, screenName, params = {}) => cacheTryGet(cache, screenName, params, getUserTweetsAndRepliesByID); +const getUserMedia = (cache, screenName, params = {}) => cacheTryGet(cache, screenName, params, getUserMediaByID); +const getUserLikes = (cache, screenName, params = {}) => cacheTryGet(cache, screenName, params, getUserLikesByID); const getSearch = async (keywords, params = {}) => gatherLegacyFromLegacyApiData(await timelineKeywords(keywords, params), 'sq-I-t-'); diff --git a/lib/v2/uber/blog.js b/lib/v2/uber/blog.js index af5c57dbd2..cad51e87cc 100644 --- a/lib/v2/uber/blog.js +++ b/lib/v2/uber/blog.js @@ -24,29 +24,28 @@ module.exports = async (ctx) => { pages = pages.map((page) => page.data); const result = await Promise.all( - pages.map( - async (page) => - await Promise.all( - page.posts.map((post) => - ctx.cache.tryGet(`${rootURL}${post.link}`, async () => { - let { data: article } = await got(`${apiURL}/wp-json/blog/v1/data`, { - searchParams: { - slug: post.link.replace(/\//g, '').replace('blog', ''), - }, - }); - article = article.article; + pages.map((page) => + Promise.all( + page.posts.map((post) => + ctx.cache.tryGet(`${rootURL}${post.link}`, async () => { + let { data: article } = await got(`${apiURL}/wp-json/blog/v1/data`, { + searchParams: { + slug: post.link.replace(/\//g, '').replace('blog', ''), + }, + }); + article = article.article; - return { - link: article.link, - title: article.title, - description: article.content, - pubDate: parseDate(article.created), - author: article.author, - category: article.categories.map((category) => category.category_name), - }; - }) - ) + return { + link: article.link, + title: article.title, + description: article.content, + pubDate: parseDate(article.created), + author: article.author, + category: article.categories.map((category) => category.category_name), + }; + }) ) + ) ) ); diff --git a/lib/v2/wechat/ce.js b/lib/v2/wechat/ce.js index f0f5658304..6f5c41058c 100644 --- a/lib/v2/wechat/ce.js +++ b/lib/v2/wechat/ce.js @@ -22,11 +22,11 @@ module.exports = async (ctx) => { ); const items = await Promise.all( - feed.items.splice(0, 10).map(async (item) => { + feed.items.splice(0, 10).map((item) => { // generally speaking, changing `item.link` of an existing route could potentially break `item.guid` // but since the route has been down for at least 8 months, it's probably safe item.link = item.link.replace(/^http:\/\//, 'https://'); - return await ctx.cache.tryGet(item.link, async () => { + return ctx.cache.tryGet(item.link, async () => { const response = await got.get(item.link, { headers: { 'User-Agent': UA, diff --git a/lib/v2/wechat/data258.js b/lib/v2/wechat/data258.js index 6e86ead612..3ed97f8c03 100644 --- a/lib/v2/wechat/data258.js +++ b/lib/v2/wechat/data258.js @@ -123,7 +123,7 @@ module.exports = async (ctx) => { throw err; } - await Promise.all(items.map(async (item) => await finishArticleItem(ctx, item, !!categoryPage))); + await Promise.all(items.map((item) => finishArticleItem(ctx, item, !!categoryPage))); ctx.state.data = { title, diff --git a/lib/v2/wechat/ershcimi.js b/lib/v2/wechat/ershcimi.js index 2772c2e8df..ceaeb39e87 100644 --- a/lib/v2/wechat/ershcimi.js +++ b/lib/v2/wechat/ershcimi.js @@ -24,7 +24,7 @@ module.exports = async (ctx) => { }) .get(); - await Promise.all(items.map(async (item) => await finishArticleItem(ctx, item))); + await Promise.all(items.map((item) => finishArticleItem(ctx, item))); ctx.state.data = { title: `微信公众号 - ${$('span.name').text()}`, diff --git a/lib/v2/wechat/feeddd.js b/lib/v2/wechat/feeddd.js index ae687f92ad..009b8b43b0 100644 --- a/lib/v2/wechat/feeddd.js +++ b/lib/v2/wechat/feeddd.js @@ -18,7 +18,7 @@ module.exports = async (ctx) => { guid: item.id, })); - items = await Promise.all(items.map(async (item) => await finishArticleItem(ctx, item))); + items = await Promise.all(items.map((item) => finishArticleItem(ctx, item))); ctx.state.data = { title: response.data.title, diff --git a/lib/v2/wechat/feeds.js b/lib/v2/wechat/feeds.js index 799ad0a16e..c28378f2f1 100644 --- a/lib/v2/wechat/feeds.js +++ b/lib/v2/wechat/feeds.js @@ -12,7 +12,7 @@ module.exports = async (ctx) => { link: item.link, guid: item.link, })); - await Promise.all(items.map(async (item) => await finishArticleItem(ctx, item))); + await Promise.all(items.map((item) => finishArticleItem(ctx, item))); ctx.state.data = { title: feed.title, diff --git a/lib/v2/wechat/mp.js b/lib/v2/wechat/mp.js index 308fb2e121..31bd633266 100755 --- a/lib/v2/wechat/mp.js +++ b/lib/v2/wechat/mp.js @@ -27,12 +27,12 @@ module.exports = async (ctx) => { // 标题,另外差一个菜单标题!求助 const mptitle = $('div.articles_header').find('a').text() + `|` + $('div.articles_header > h2.rich_media_title').text(); const articledata = await Promise.all( - list.map(async (item) => { + list.map((item) => { const single = { link: item.link, guid: item.link, }; - return await finishArticleItem(ctx, single); + return finishArticleItem(ctx, single); }) ); ctx.state.data = { diff --git a/lib/v2/wechat/msgalbum.js b/lib/v2/wechat/msgalbum.js index 0fcb358332..1a65f9c44a 100644 --- a/lib/v2/wechat/msgalbum.js +++ b/lib/v2/wechat/msgalbum.js @@ -15,7 +15,7 @@ module.exports = async (ctx) => { const list = $('li').get(); const mptitle = $('.album__author-name').text() + `|` + $('.album__label-title').text(); const articledata = await Promise.all( - list.map(async (item) => { + list.map((item) => { const link = $(item).attr('data-link').replace('http://', 'https://'); const title = $(item).attr('data-title'); const single = { @@ -23,7 +23,7 @@ module.exports = async (ctx) => { link, guid: link, }; - return await finishArticleItem(ctx, single); + return finishArticleItem(ctx, single); }) ); ctx.state.data = { diff --git a/lib/v2/wfu/news.js b/lib/v2/wfu/news.js index 66feb0be19..461dc66688 100644 --- a/lib/v2/wfu/news.js +++ b/lib/v2/wfu/news.js @@ -80,7 +80,7 @@ module.exports = async (ctx) => { // 对于列表的每一项, 单独获取 时间与详细内容 // eslint-disable-next-line no-return-await - const other = await ctx.cache.tryGet($item_url, async () => await load($item_url)); + const other = await ctx.cache.tryGet($item_url, () => load($item_url)); // 合并解析后的结果集作为该篇文章最终的输出结果 return { ...single, ...other }; }) diff --git a/lib/v2/who/news-room.js b/lib/v2/who/news-room.js index c37c5ef102..fb850fc7b6 100644 --- a/lib/v2/who/news-room.js +++ b/lib/v2/who/news-room.js @@ -43,28 +43,27 @@ module.exports = async (ctx) => { } const items = await Promise.all( - list.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); - const matches = detailResponse.data.match(/"headline":"(.*)","description":"(.*)","datePublished":"(.*)","image"/); + const matches = detailResponse.data.match(/"headline":"(.*)","description":"(.*)","datePublished":"(.*)","image"/); - if (matches) { - item.title = matches[1]; - item.description = matches[2]; - item.pubDate = parseDate(matches[3]); - } else { - const content = cheerio.load(detailResponse.data); + if (matches) { + item.title = matches[1]; + item.description = matches[2]; + item.pubDate = parseDate(matches[3]); + } else { + const content = cheerio.load(detailResponse.data); - item.description = content('.sf-content-block').html(); - } + item.description = content('.sf-content-block').html(); + } - return item; - }) + return item; + }) ) ); diff --git a/lib/v2/who/news.js b/lib/v2/who/news.js index 0d1781106f..309a33cc98 100644 --- a/lib/v2/who/news.js +++ b/lib/v2/who/news.js @@ -20,18 +20,17 @@ module.exports = async (ctx) => { })); const items = await Promise.all( - list.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); - item.description = detailResponse.data.match(/"description":"(.*)","datePublished"/)[1]; + item.description = detailResponse.data.match(/"description":"(.*)","datePublished"/)[1]; - return item; - }) + return item; + }) ) ); diff --git a/lib/v2/wp-china/news.js b/lib/v2/wp-china/news.js index 8ad96177c0..368b4b6deb 100644 --- a/lib/v2/wp-china/news.js +++ b/lib/v2/wp-china/news.js @@ -33,19 +33,18 @@ module.exports = async (ctx) => { .get(); const items = await Promise.all( - list.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = cheerio.load(detailResponse.data); + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); - item.description = content('.wb100').html(); + item.description = content('.wb100').html(); - return item; - }) + return item; + }) ) ); diff --git a/lib/v2/wyzxwk/article.js b/lib/v2/wyzxwk/article.js index 82e42862b0..9cd9c593af 100644 --- a/lib/v2/wyzxwk/article.js +++ b/lib/v2/wyzxwk/article.js @@ -29,31 +29,30 @@ module.exports = async (ctx) => { }); items = await Promise.all( - items.map( - async (item) => - await ctx.cache.tryGet(item.link, async () => { - if (item.link.indexOf('wyzxwk.com') > 0) { - try { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = cheerio.load(detailResponse.data); + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + if (item.link.indexOf('wyzxwk.com') > 0) { + try { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); - content('.zs-modal-body').prev().nextAll().remove(); + content('.zs-modal-body').prev().nextAll().remove(); - const pubDate = detailResponse.data.match(/(\d{4}-\d{2}-\d{2})<\/span>/); - if (pubDate) { - item.pubDate = parseDate(pubDate[1], 'YYYY-MM-DD'); - } - - item.description = content('article').html(); - } catch (e) { - item.description = ''; + const pubDate = detailResponse.data.match(/(\d{4}-\d{2}-\d{2})<\/span>/); + if (pubDate) { + item.pubDate = parseDate(pubDate[1], 'YYYY-MM-DD'); } + + item.description = content('article').html(); + } catch (e) { + item.description = ''; } - return item; - }) + } + return item; + }) ) ); diff --git a/lib/v2/yicai/utils.js b/lib/v2/yicai/utils.js index 970e15bbab..6414d8cfbd 100644 --- a/lib/v2/yicai/utils.js +++ b/lib/v2/yicai/utils.js @@ -28,7 +28,7 @@ module.exports = { }), })); - return await Promise.all( + return Promise.all( items.map((item) => tryGet(item.link, async () => { const detailResponse = await got({ diff --git a/test/middleware/anti-hotlink.js b/test/middleware/anti-hotlink.js index 3447c47d45..ea6410f978 100644 --- a/test/middleware/anti-hotlink.js +++ b/test/middleware/anti-hotlink.js @@ -200,13 +200,13 @@ const testAntiHotlink = async (path, expectObj, query) => { return parsed; }; -const expectImgOrigin = async (query) => await testAntiHotlink('/test/complicated', expects.complicated.origin, query); -const expectImgProcessed = async (query) => await testAntiHotlink('/test/complicated', expects.complicated.processed, query); -const expectImgUrlencoded = async (query) => await testAntiHotlink('/test/complicated', expects.complicated.urlencoded, query); -const expectMultimediaOrigin = async (query) => await testAntiHotlink('/test/multimedia', expects.multimedia.origin, query); -const expectMultimediaRelayed = async (query) => await testAntiHotlink('/test/multimedia', expects.multimedia.relayed, query); -const expectMultimediaPartlyRelayed = async (query) => await testAntiHotlink('/test/multimedia', expects.multimedia.partlyRelayed, query); -const expectMultimediaWrappedInIframe = async (query) => await testAntiHotlink('/test/multimedia', expects.multimedia.wrappedInIframe, query); +const expectImgOrigin = (query) => testAntiHotlink('/test/complicated', expects.complicated.origin, query); +const expectImgProcessed = (query) => testAntiHotlink('/test/complicated', expects.complicated.processed, query); +const expectImgUrlencoded = (query) => testAntiHotlink('/test/complicated', expects.complicated.urlencoded, query); +const expectMultimediaOrigin = (query) => testAntiHotlink('/test/multimedia', expects.multimedia.origin, query); +const expectMultimediaRelayed = (query) => testAntiHotlink('/test/multimedia', expects.multimedia.relayed, query); +const expectMultimediaPartlyRelayed = (query) => testAntiHotlink('/test/multimedia', expects.multimedia.partlyRelayed, query); +const expectMultimediaWrappedInIframe = (query) => testAntiHotlink('/test/multimedia', expects.multimedia.wrappedInIframe, query); describe('anti-hotlink', () => { it('template-legacy', async () => {