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
This commit is contained in:
Bin Wang 2022-03-21 12:06:35 -04:00 committed by GitHub
parent 10118b004f
commit 6b3d21438e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -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);

View File

@ -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 &&