From f6fca3483a228f793ca8115ba6fd1e1f278d76ea Mon Sep 17 00:00:00 2001 From: zytomorrow Date: Sun, 8 Mar 2020 23:13:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E8=A7=A3=E9=99=A4oauth2=E6=8E=88=E6=9D=83=E5=90=8Etoken?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E6=97=A0=E6=B3=95=E5=88=B7=E6=96=B0=20(#4156?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/weibo/timeline.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/routes/weibo/timeline.js b/lib/routes/weibo/timeline.js index ed91e75c4..63ee62727 100644 --- a/lib/routes/weibo/timeline.js +++ b/lib/routes/weibo/timeline.js @@ -8,6 +8,16 @@ module.exports = async (ctx) => { if (token) { const response = await got.get(`https://api.weibo.com/2/statuses/home_timeline.json?access_token=${token}&count=100&feature=${feature}`); + // 检查token失效 + if (response.data.error !== undefined) { + const { app_key = '', redirect_url = ctx.request.origin + '/weibo/timeline/0' } = config.weibo; + + ctx.status = 302; + ctx.set({ + 'Cache-Control': 'no-cache', + }); + ctx.redirect(`https://api.weibo.com/oauth2/authorize?client_id=${app_key}&redirect_uri=${redirect_url}`); + } // 获取所有表情 const weiboEmotion = await ctx.cache.tryGet('weiboEmotion', async () => { const tmpEmotionList = {};