Skip to content

Commit eee59e4

Browse files
authored
fix(route/douyu): simplify item creation for live stream titles (#20792)
1 parent 201ce43 commit eee59e4

File tree

1 file changed

+15
-29
lines changed

1 file changed

+15
-29
lines changed

lib/routes/douyu/room.ts

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Route } from '@/types';
2-
import got from '@/utils/got';
2+
import ofetch from '@/utils/ofetch';
33

44
export const route: Route = {
55
path: '/room/:id',
@@ -31,49 +31,35 @@ async function handler(ctx) {
3131
let item;
3232
let room_thumb;
3333
try {
34-
const response = await got({
35-
method: 'get',
36-
url: `https://www.douyu.com/betard/${id}`,
37-
});
34+
const response = await ofetch(`https://www.douyu.com/betard/${id}`);
3835

39-
if (!response.data.room) {
36+
if (!response.room) {
4037
throw new Error('Invalid response');
4138
}
4239

43-
data = response.data.room;
40+
data = response.room;
4441
room_thumb = data.room_pic;
4542

4643
if (data.show_status === 1) {
47-
item =
48-
data.videoLoop === 1
49-
? [
50-
{
51-
title: `视频轮播: ${data.room_name}`,
52-
pubDate: new Date(data.show_time * 1000).toUTCString(),
53-
guid: data.show_time,
54-
link: `https://www.douyu.com/${id}`,
55-
},
56-
]
57-
: [
58-
{
59-
title: `开播: ${data.room_name}`,
60-
pubDate: new Date(data.show_time * 1000).toUTCString(),
61-
guid: data.show_time,
62-
link: `https://www.douyu.com/${id}`,
63-
},
64-
];
44+
item = [
45+
{
46+
title: `${data.videoLoop === 1 ? '视频轮播' : '开播'}: ${data.room_name}`,
47+
pubDate: new Date(data.show_time * 1000).toUTCString(),
48+
guid: data.show_time,
49+
link: `https://www.douyu.com/${id}`,
50+
description: `<img src="${room_thumb}">`,
51+
},
52+
];
6553
}
6654
// make a fallback to the old api
6755
} catch {
68-
const response = await got({
69-
method: 'get',
70-
url: `http://open.douyucdn.cn/api/RoomApi/room/${id}`,
56+
const response = await ofetch(`http://open.douyucdn.cn/api/RoomApi/room/${id}`, {
7157
headers: {
7258
Referer: `https://www.douyu.com/${id}`,
7359
},
7460
});
7561

76-
data = response.data.data;
62+
data = response.data;
7763
room_thumb = data.room_thumb;
7864

7965
if (data.online !== 0) {

0 commit comments

Comments
 (0)