diff --git a/lib/routes/bilibili/ranking.js b/lib/routes/bilibili/ranking.js
index 85917b8880..3e20bbd83d 100644
--- a/lib/routes/bilibili/ranking.js
+++ b/lib/routes/bilibili/ranking.js
@@ -1,4 +1,5 @@
const got = require('@/utils/got');
+const utils = require('./utils');
module.exports = async (ctx) => {
const rid = ctx.params.rid || '0';
@@ -7,7 +8,7 @@ module.exports = async (ctx) => {
const arc_type1 = arc_type === '0' ? '全部投稿' : '近期投稿';
const rid_1 = ['0', '1', '168', '3', '129', '4', '36', '160', '119', '155', '5', '181'];
const rid_2 = ['全站', '动画', '国创相关', '音乐', '舞蹈', '游戏', '科技', '生活', '鬼畜', '时尚', '娱乐', '影视'];
- const rid_i = rid_1.indexOf(arc_type);
+ const rid_i = rid_1.indexOf(rid + '');
const rid_type = rid_2[rid_i];
const response = await got({
method: 'get',
@@ -27,15 +28,11 @@ module.exports = async (ctx) => {
list = list.concat(list[i].others);
}
}
-
+ list = list.map((i) => i.aid);
+ const resultItems = await utils.ProcessFeed(list, ctx.cache);
ctx.state.data = {
title: `bilibili ${day}日排行榜-${rid_type}-${arc_type1}`,
link: `https://www.bilibili.com/ranking/all/${rid}/0/${day}`,
- item: list.map((item) => ({
- title: item.title,
- description: `作者:${item.author}
播放量:${item.play}
时长:${item.duration}
综合得分:${item.pts}
弹幕:${item.video_review}
`,
- link: `https://www.bilibili.com/video/av${item.aid}`,
- author: item.author,
- })),
+ item: resultItems,
};
};
diff --git a/lib/routes/bilibili/utils.js b/lib/routes/bilibili/utils.js
new file mode 100644
index 0000000000..988f94e473
--- /dev/null
+++ b/lib/routes/bilibili/utils.js
@@ -0,0 +1,35 @@
+const got = require('@/utils/got');
+
+async function load(aid) {
+ const response = await got({
+ method: 'get',
+ url: `https://api.bilibili.com/x/article/archives?ids=${aid}`,
+ });
+ return response.data;
+}
+
+const ProcessFeed = async (list, caches) =>
+ await Promise.all(
+ list
+ .filter(async (aid) => {
+ const data = await caches.tryGet('av' + aid, async () => await load(aid));
+ return data.code == 0;
+ })
+ .map(async (aid) => {
+ let data = await caches.tryGet('av' + aid, async () => await load(aid));
+ data = data.data[aid + ''];
+ const single = {
+ title: data.title,
+ description: data.desc,
+ pubDate: new Date(data.pubdate * 1000).toUTCString(),
+ author: data.owner.name,
+ link: `https://www.bilibili.com/video/av${aid}`,
+ guid: `https://www.bilibili.com/video/av${aid}`,
+ };
+ return Promise.resolve(single);
+ })
+ );
+
+module.exports = {
+ ProcessFeed,
+};