From d581d778c693f253b81a71684841af69527b5cce Mon Sep 17 00:00:00 2001 From: Derek Date: Mon, 20 Jun 2022 18:22:43 +0800 Subject: [PATCH] fix(route): use `list = await Promise.all(...)` instead of `await Promise.all(...)`; (#9985) * feat(fix): use `list = await Promise.all(...)` instead of `await Promise.all(..)` * feat: use `const` instead of `let` for items * fix: scitation * revert: scitation * update --- lib/v2/elsevier/issue.js | 4 ++-- lib/v2/elsevier/journal.js | 4 ++-- lib/v2/heu/gx/list.js | 4 ++-- lib/v2/heu/job/list.js | 4 ++-- lib/v2/heu/uae/list.js | 4 ++-- lib/v2/heu/yjsy/list.js | 4 ++-- lib/v2/scitation/journal.js | 4 ++-- lib/v2/scitation/section.js | 4 ++-- lib/v2/springer/journal.js | 4 ++-- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/v2/elsevier/issue.js b/lib/v2/elsevier/issue.js index 19a26fbfc..95f2ef7e6 100644 --- a/lib/v2/elsevier/issue.js +++ b/lib/v2/elsevier/issue.js @@ -37,7 +37,7 @@ module.exports = async (ctx) => { art(path.join(__dirname, 'templates/description.art'), { item, }); - await Promise.all( + const items = await Promise.all( list.map((item) => ctx.cache.tryGet(item.link, async () => { const response2 = await got(`${host}/science/article/pii/${item.id}`, { @@ -57,6 +57,6 @@ module.exports = async (ctx) => { ctx.state.data = { title: `${jrnlName} - ${issue}`, link: issueUrl, - item: list, + item: items, }; }; diff --git a/lib/v2/elsevier/journal.js b/lib/v2/elsevier/journal.js index 9fbe226ae..c7d4773e8 100644 --- a/lib/v2/elsevier/journal.js +++ b/lib/v2/elsevier/journal.js @@ -48,7 +48,7 @@ module.exports = async (ctx) => { art(path.join(__dirname, 'templates/description.art'), { item, }); - await Promise.all( + const items = await Promise.all( list.map((item) => ctx.cache.tryGet(item.link, async () => { const response3 = await got(`${host}/science/article/pii/${item.id}`, { @@ -67,6 +67,6 @@ module.exports = async (ctx) => { ctx.state.data = { title: jrnlName, link: jrnlUrl, - item: list, + item: items, }; }; diff --git a/lib/v2/heu/gx/list.js b/lib/v2/heu/gx/list.js index c4c9c001d..c8b14e7f8 100644 --- a/lib/v2/heu/gx/list.js +++ b/lib/v2/heu/gx/list.js @@ -47,7 +47,7 @@ module.exports = async (ctx) => { }) .get(); - await Promise.all( + const items = await Promise.all( list.map((item) => ctx.cache.tryGet(item.link, async () => { if (item.link.indexOf('info') !== -1) { @@ -68,6 +68,6 @@ module.exports = async (ctx) => { ctx.state.data = { title: '工学-' + bigTitle, link: toUrl, - item: list, + item: items, }; }; diff --git a/lib/v2/heu/job/list.js b/lib/v2/heu/job/list.js index 15ac9760d..f3c4cff06 100644 --- a/lib/v2/heu/job/list.js +++ b/lib/v2/heu/job/list.js @@ -44,7 +44,7 @@ module.exports = async (ctx) => { }) .get(); - await Promise.all( + const items = await Promise.all( list.map((item) => ctx.cache.tryGet(item.link, async () => { if (item.link.indexOf('HrbeuJY') !== -1) { @@ -65,6 +65,6 @@ module.exports = async (ctx) => { ctx.state.data = { title: '就业服务平台-' + idMap[id].name, link: idMap[id].url, - item: list, + item: items, }; }; diff --git a/lib/v2/heu/uae/list.js b/lib/v2/heu/uae/list.js index 098bc1a1c..41a29cf1c 100644 --- a/lib/v2/heu/uae/list.js +++ b/lib/v2/heu/uae/list.js @@ -35,7 +35,7 @@ module.exports = async (ctx) => { }) .get(); - await Promise.all( + const items = await Promise.all( list.map((item) => ctx.cache.tryGet(item.link, async () => { if (item.link.indexOf('page.htm') !== -1) { @@ -57,6 +57,6 @@ module.exports = async (ctx) => { ctx.state.data = { title: '水声学院-' + bigTitle, link: rootUrl.concat('/', id, '/list.htm'), - item: list, + item: items, }; }; diff --git a/lib/v2/heu/yjsy/list.js b/lib/v2/heu/yjsy/list.js index 28549faba..7f2a0a3a6 100644 --- a/lib/v2/heu/yjsy/list.js +++ b/lib/v2/heu/yjsy/list.js @@ -39,7 +39,7 @@ module.exports = async (ctx) => { }) .get(); - await Promise.all( + const items = await Promise.all( list.map((item) => ctx.cache.tryGet(item.link, async () => { if (item.link.indexOf('page.htm') !== -1) { @@ -60,6 +60,6 @@ module.exports = async (ctx) => { ctx.state.data = { title: '研究生院-' + bigTitle, link: rootUrl.concat('/', id, '/list.htm'), - item: list, + item: items, }; }; diff --git a/lib/v2/scitation/journal.js b/lib/v2/scitation/journal.js index cd5cb2bdf..68ebe3efc 100644 --- a/lib/v2/scitation/journal.js +++ b/lib/v2/scitation/journal.js @@ -39,7 +39,7 @@ module.exports = async (ctx) => { art(path.join(__dirname, 'templates/description.art'), { item, }); - await Promise.all( + const items = await Promise.all( list.map((item) => ctx.cache.tryGet(item.link, async () => { const response2 = await got.post(`${host}/action/PB2showAjaxAbstract`, { @@ -62,6 +62,6 @@ module.exports = async (ctx) => { ctx.state.data = { title: jrnlName, link: jrnlUrl, - item: list, + item: items, }; }; diff --git a/lib/v2/scitation/section.js b/lib/v2/scitation/section.js index 5ecac8c4b..507a91bf7 100644 --- a/lib/v2/scitation/section.js +++ b/lib/v2/scitation/section.js @@ -25,13 +25,13 @@ module.exports = async (ctx) => { })) .get(); - let list; let ifContainSection = false; for (let i = 0, l = section.length; i < l; i++) { if (section[i].name === sec) { ifContainSection = true; } } + let list; if (ifContainSection === true) { const secUrl = `${issueUrl}?tocSection=${sec}`; const response2 = await got(secUrl, { @@ -60,7 +60,7 @@ module.exports = async (ctx) => { art(path.join(__dirname, 'templates/description.art'), { item, }); - await Promise.all( + list = await Promise.all( list.map((item) => ctx.cache.tryGet(item.link, async () => { const response3 = await got.post(host.concat('/action/PB2showAjaxAbstract'), { diff --git a/lib/v2/springer/journal.js b/lib/v2/springer/journal.js index 67efd638b..9e3565bf7 100644 --- a/lib/v2/springer/journal.js +++ b/lib/v2/springer/journal.js @@ -50,7 +50,7 @@ module.exports = async (ctx) => { art(path.join(__dirname, 'templates/description.art'), { item, }); - await Promise.all( + const items = await Promise.all( list.map((item) => ctx.cache.tryGet(item.link, async () => { const response3 = await got(item.link, { @@ -67,6 +67,6 @@ module.exports = async (ctx) => { ctx.state.data = { title: jrnlName, link: jrnlUrl, - item: list, + item: items, }; };