fix: 修复手动解除oauth2授权后token缓存无法刷新 (#4156)

This commit is contained in:
zytomorrow 2020-03-08 23:13:47 +08:00 committed by GitHub
parent 7651dd0018
commit f6fca3483a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -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 = {};