|
1 | 1 | import type { Route } from '@/types'; |
2 | | -import got from '@/utils/got'; |
| 2 | +import ofetch from '@/utils/ofetch'; |
3 | 3 |
|
4 | 4 | export const route: Route = { |
5 | 5 | path: '/room/:id', |
@@ -31,49 +31,35 @@ async function handler(ctx) { |
31 | 31 | let item; |
32 | 32 | let room_thumb; |
33 | 33 | 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}`); |
38 | 35 |
|
39 | | - if (!response.data.room) { |
| 36 | + if (!response.room) { |
40 | 37 | throw new Error('Invalid response'); |
41 | 38 | } |
42 | 39 |
|
43 | | - data = response.data.room; |
| 40 | + data = response.room; |
44 | 41 | room_thumb = data.room_pic; |
45 | 42 |
|
46 | 43 | 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 | + ]; |
65 | 53 | } |
66 | 54 | // make a fallback to the old api |
67 | 55 | } 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}`, { |
71 | 57 | headers: { |
72 | 58 | Referer: `https://www.douyu.com/${id}`, |
73 | 59 | }, |
74 | 60 | }); |
75 | 61 |
|
76 | | - data = response.data.data; |
| 62 | + data = response.data; |
77 | 63 | room_thumb = data.room_thumb; |
78 | 64 |
|
79 | 65 | if (data.online !== 0) { |
|
0 commit comments