From 6b3d21438e50ae376c7ae465f5c0ee559c0318a2 Mon Sep 17 00:00:00 2001 From: Bin Wang Date: Mon, 21 Mar 2022 12:06:35 -0400 Subject: [PATCH] feat(route): add icon and logo to Bilibili atom feed (#9353) Fetch Bilibili user avatar and use it as icon and logo for atom feed --- lib/v2/bilibili/cache.js | 17 +++++++++++++++++ lib/v2/bilibili/video.js | 4 +++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/v2/bilibili/cache.js b/lib/v2/bilibili/cache.js index bc2139cf0..82c84e3d4 100644 --- a/lib/v2/bilibili/cache.js +++ b/lib/v2/bilibili/cache.js @@ -16,6 +16,23 @@ module.exports = { } return name; }, + getUsernameAndFaceFromUID: async (ctx, uid) => { + const nameKey = 'bili-username-from-uid-' + uid; + const faceKey = 'bili-userface-from-uid-' + uid; + let name = await ctx.cache.get(nameKey); + let face = await ctx.cache.get(faceKey); + if (!name) { + const nameResponse = await got({ + method: 'get', + url: `https://api.bilibili.com/x/space/acc/info?mid=${uid}&jsonp=jsonp`, + }); + name = nameResponse.data.data.name; + face = nameResponse.data.data.face; + ctx.cache.set(nameKey, name); + ctx.cache.set(faceKey, face); + } + return [name, face]; + }, getLiveIDFromShortID: async (ctx, shortID) => { const key = `bili-liveID-from-shortID-${shortID}`; let liveID = await ctx.cache.get(key); diff --git a/lib/v2/bilibili/video.js b/lib/v2/bilibili/video.js index 8e52a8d26..0f728233c 100644 --- a/lib/v2/bilibili/video.js +++ b/lib/v2/bilibili/video.js @@ -5,7 +5,7 @@ const utils = require('./utils'); module.exports = async (ctx) => { const uid = ctx.params.uid; const disableEmbed = ctx.params.disableEmbed; - const name = await cache.getUsernameFromUID(ctx, uid); + const [name, face] = await cache.getUsernameAndFaceFromUID(ctx, uid); const response = await got({ method: 'get', @@ -20,6 +20,8 @@ module.exports = async (ctx) => { title: `${name} 的 bilibili 空间`, link: `https://space.bilibili.com/${uid}`, description: `${name} 的 bilibili 空间`, + logo: face, + icon: face, item: data.data && data.data.list &&