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:
parent
10118b004f
commit
6b3d21438e
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 &&
|
||||
|
|
|
|||
Loading…
Reference in New Issue