(req: NextRequest)
| 20 | export const revalidate = 10 |
| 21 | |
| 22 | export const GET = async (req: NextRequest): Promise<Response> => { |
| 23 | const liveId = req.nextUrl.searchParams.get('liveId') |
| 24 | const response = new NextServerResponse() |
| 25 | if (!liveId) { |
| 26 | return response.status(400).end() |
| 27 | } |
| 28 | const queryClient = getQueryClient() |
| 29 | const res = await queryClient.fetchQuery({ |
| 30 | queryKey: ['bilibili-live', liveId], |
| 31 | queryFn: async () => { |
| 32 | return fetch( |
| 33 | `https://api.live.bilibili.com/xlive/web-room/v2/index/getRoomPlayInfo?room_id=${liveId}&protocol=0,1&format=0,1,2&codec=0,1&qn=0&platform=web&ptype=8&dolby=5`, |
| 34 | { |
| 35 | headers: requestHeader, |
| 36 | }, |
| 37 | ) |
| 38 | .then((res) => res.json()) |
| 39 | .catch(() => null) |
| 40 | }, |
| 41 | }) |
| 42 | |
| 43 | if (!res?.data) { |
| 44 | return response.end() |
| 45 | } |
| 46 | |
| 47 | if (!res?.data?.playurl_info) { |
| 48 | return response.end() |
| 49 | } |
| 50 | const userInfo = await fetch( |
| 51 | `https://api.live.bilibili.com/live_user/v1/UserInfo/get_anchor_in_room?roomid=${liveId}`, |
| 52 | { |
| 53 | headers: requestHeader, |
| 54 | }, |
| 55 | ) |
| 56 | .then((res) => res.json()) |
| 57 | .catch(() => null) |
| 58 | |
| 59 | if (!userInfo) { |
| 60 | return response.end() |
| 61 | } |
| 62 | |
| 63 | const { info } = (userInfo as BLUser).data |
| 64 | return response.json({ ...info }) |
| 65 | } |
nothing calls this directly
no test coverage detected