MCPcopy
hub / github.com/Innei/Shiro / GET

Function GET

src/app/api/bilibili/check_live/route.ts:22–65  ·  view source on GitHub ↗
(req: NextRequest)

Source from the content-addressed store, hash-verified

20export const revalidate = 10
21
22export 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}

Callers

nothing calls this directly

Calls 5

endMethod · 0.95
statusMethod · 0.95
jsonMethod · 0.95
getQueryClientFunction · 0.90
fetchFunction · 0.85

Tested by

no test coverage detected