From af2c474a7451e75116c5ce30bfb0f7df332c768d Mon Sep 17 00:00:00 2001 From: cssxsh <32539286+cssxsh@users.noreply.github.com> Date: Fri, 18 Oct 2019 14:41:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20X-mol=20=E6=9C=9F=E5=88=8A=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=96=87=E7=AB=A0=E6=B2=A1=E6=9C=89=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E6=97=B6=E6=8A=A5=E9=94=99=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5=20(#3283)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/x-mol/paper.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/routes/x-mol/paper.js b/lib/routes/x-mol/paper.js index 0c88ffe27..ba1d92230 100644 --- a/lib/routes/x-mol/paper.js +++ b/lib/routes/x-mol/paper.js @@ -29,20 +29,22 @@ module.exports = async (ctx) => { const title = a.text(); const link = utils.host + a.attr('href'); - const imageId = news - .find('.magazine-pic') - .attr('id') - .substring(9); - const getLink = utils.host + '/attachment/getImgUrl'; + const picId = news.find('.magazine-pic').attr('id'); const noPic = utils.host + '/css/images/nothesispic.jpg'; - const imageUrl = await ctx.cache.tryGet(getLink, async () => { - const result = await got.get(getLink, { - params: { - attachmentId: imageId, - }, - }); - return result.data; - }); + let imageUrl = noPic; + if (picId) { + const imageId = picId.substring(9); + const getLink = utils.host + '/attachment/getImgUrl'; + imageUrl = + (await ctx.cache.tryGet(getLink, async () => { + const result = await got.get(getLink, { + params: { + attachmentId: imageId, + }, + }); + return result.data; + })) || noPic; + } const image = imageUrl || noPic; const text = $(element) .find('.magazine-description')