From 75fc439dafdbb996a26eeed147c5134e7d0ec3f7 Mon Sep 17 00:00:00 2001 From: Tony Date: Sun, 23 Apr 2023 10:37:32 -0700 Subject: [PATCH] fix(route): zhihu private answers (#12379) * fix(route): zhihu answers * fix: more robust caching --- lib/v2/zhihu/answers.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/v2/zhihu/answers.js b/lib/v2/zhihu/answers.js index d5789a404..dd43a0cd0 100644 --- a/lib/v2/zhihu/answers.js +++ b/lib/v2/zhihu/answers.js @@ -19,16 +19,20 @@ module.exports = async (ctx) => { let name = data[0].author.name; if (name === '知乎用户') { - const info = await got({ - method: 'get', - url: `https://www.zhihu.com/api/v4/members/${id}/activities?limit=1`, - headers: { - ...utils.header, - Referer: `https://www.zhihu.com/people/${id}/activities`, - Authorization: 'oauth c3cef7c66a1843f8b3a9e6a1e3160e20', // hard-coded in js - }, + const userProfile = await ctx.cache.tryGet(`zhihu:profile:${id}`, async () => { + const apiPath = `/api/v4/profile/${id}/infinity`; + + const { data } = await got({ + method: 'get', + url: `https://www.zhihu.com${apiPath}`, + headers: { + ...utils.header, + Referer: `https://www.zhihu.com/people/${id}`, + }, + }); + return data.data; }); - name = info.data.data[0].actor.name; + name = userProfile.name; } const items = await Promise.all(