diff --git a/lib/routes/bilibili/cache.ts b/lib/routes/bilibili/cache.ts index 810063880e..d2010fbbae 100644 --- a/lib/routes/bilibili/cache.ts +++ b/lib/routes/bilibili/cache.ts @@ -147,11 +147,11 @@ const getUsernameAndFaceFromUID = async (uid) => { if (nameResponse.data.name) { name = nameResponse.data.name; face = nameResponse.data.face; + cache.set(nameKey, nameResponse.data.name); + cache.set(faceKey, nameResponse.data.face); } else { logger.error(`Error when visiting /x/space/wbi/acc/info: ${JSON.stringify(nameResponse)}`); } - cache.set(nameKey, name); - cache.set(faceKey, face); } return [name, face]; }; diff --git a/lib/routes/bilibili/dynamic.ts b/lib/routes/bilibili/dynamic.ts index 36138f0e71..492b7f8ed2 100644 --- a/lib/routes/bilibili/dynamic.ts +++ b/lib/routes/bilibili/dynamic.ts @@ -271,11 +271,16 @@ async function handler(ctx) { } const items = (body as BilibiliWebDynamicResponse)?.data?.items; - const usernameAndFace = await cacheIn.getUsernameAndFaceFromUID(uid); - const author = usernameAndFace[0] || items[0]?.modules?.module_author?.name; - const face = usernameAndFace[1] || items[0]?.modules?.module_author?.face; - cache.set(`bili-username-from-uid-${uid}`, author); - cache.set(`bili-userface-from-uid-${uid}`, face); + let author = items[0]?.modules?.module_author?.name; + let face = items[0]?.modules?.module_author?.face; + if (!face || !author) { + const usernameAndFace = await cacheIn.getUsernameAndFaceFromUID(uid); + author = usernameAndFace[0] || items[0]?.modules?.module_author?.name; + face = usernameAndFace[1] || items[0]?.modules?.module_author?.face; + } else { + cache.set(`bili-username-from-uid-${uid}`, author); + cache.set(`bili-userface-from-uid-${uid}`, face); + } const rssItems = await Promise.all( items diff --git a/lib/routes/bilibili/video.ts b/lib/routes/bilibili/video.ts index 91eccd8c01..959e919d2b 100644 --- a/lib/routes/bilibili/video.ts +++ b/lib/routes/bilibili/video.ts @@ -39,7 +39,6 @@ async function handler(ctx: Context) { const dmImgList = utils.getDmImgList(); const dmImgInter = utils.getDmImgInter(); const renderData = await cache.getRenderData(uid); - const [name, face] = await cache.getUsernameAndFaceFromUID(uid); const params = utils.addWbiVerifyInfo( utils.addRenderData(utils.addDmVerifyInfoWithInter(`mid=${uid}&ps=30&tid=0&pn=1&keyword=&order=pubdate&platform=web&web_location=1550101&order_avoided=true`, dmImgList, dmImgInter), renderData), @@ -57,6 +56,10 @@ async function handler(ctx: Context) { throw new Error(`Got error code ${data.code} while fetching: ${data.message}`); } + const usernameAndFace = await cache.getUsernameAndFaceFromUID(uid); + const name = usernameAndFace[0] || data.data.list.vlist[0]?.author; + const face = usernameAndFace[1]; + return { title: `${name} 的 bilibili 空间`, link: `https://space.bilibili.com/${uid}`,