diff --git a/lib/routes/bilibili/cache.ts b/lib/routes/bilibili/cache.ts
index 395f1b0f9a9454..0bd54c3bac9ac7 100644
--- a/lib/routes/bilibili/cache.ts
+++ b/lib/routes/bilibili/cache.ts
@@ -169,15 +169,15 @@ const getLiveIDFromShortID = (shortID) => {
});
};
-const getUsernameFromLiveID = (liveID) => {
- const key = `bili-username-from-liveID-${liveID}`;
+const getUserInfoFromLiveID = (liveID) => {
+ const key = `bili-userinfo-from-liveID-${liveID}`;
return cache.tryGet(key, async () => {
const { data: nameResponse } = await got(`https://api.live.bilibili.com/live_user/v1/UserInfo/get_anchor_in_room?roomid=${liveID}`, {
headers: {
Referer: `https://live.bilibili.com/${liveID}`,
},
});
- return nameResponse.data.info.uname;
+ return nameResponse.data.info;
});
};
@@ -280,7 +280,7 @@ export default {
getUsernameFromUID,
getUsernameAndFaceFromUID,
getLiveIDFromShortID,
- getUsernameFromLiveID,
+ getUserInfoFromLiveID,
getVideoNameFromId,
getCidFromId,
getAidFromBvid,
diff --git a/lib/routes/bilibili/live-room.ts b/lib/routes/bilibili/live-room.ts
index 35a50c5f168170..7285da7adf9468 100644
--- a/lib/routes/bilibili/live-room.ts
+++ b/lib/routes/bilibili/live-room.ts
@@ -1,6 +1,9 @@
-import { Route } from '@/types';
-import got from '@/utils/got';
+import { DataItem, Route } from '@/types';
+import ofetch from '@/utils/ofetch';
import cache from './cache';
+import { decodeHTML } from 'entities';
+import { parseDate } from '@/utils/parse-date';
+import timezone from '@/utils/timezone';
export const route: Route = {
path: '/live/room/:roomID',
@@ -32,33 +35,32 @@ async function handler(ctx) {
if (Number.parseInt(roomID, 10) < 10000) {
roomID = await cache.getLiveIDFromShortID(roomID);
}
- const name = await cache.getUsernameFromLiveID(roomID);
+ const info = await cache.getUserInfoFromLiveID(roomID);
- const response = await got({
- method: 'get',
- url: `https://api.live.bilibili.com/room/v1/Room/get_info?room_id=${roomID}&from=room`,
+ const response = await ofetch(`https://api.live.bilibili.com/room/v1/Room/get_info?room_id=${roomID}&from=room`, {
headers: {
Referer: `https://live.bilibili.com/${roomID}`,
},
});
- const data = response.data.data;
+ const data = response.data;
- const liveItem = [];
+ const liveItem: DataItem[] = [];
if (data.live_status === 1) {
liveItem.push({
title: `${data.title} ${data.live_time}`,
- description: `${data.title}
${data.description}`,
- pubDate: new Date(data.live_time.replace(' ', 'T') + '+08:00').toUTCString(),
+ description: `
${decodeHTML(data.description)}`,
+ pubDate: timezone(parseDate(data.live_time), 8),
guid: `https://live.bilibili.com/${roomID} ${data.live_time}`,
link: `https://live.bilibili.com/${roomID}`,
});
}
return {
- title: `${name} 直播间开播状态`,
+ title: `${info.uname} 直播间开播状态`,
link: `https://live.bilibili.com/${roomID}`,
- description: `${name} 直播间开播状态`,
+ description: `${info.uname} 直播间开播状态`,
+ image: info.face,
item: liveItem,
allowEmpty: true,
};