@@ -288,8 +288,7 @@ app.get(['/api/status', '/status'], async (req, res) => {
288288
289289// 获取排行榜
290290app . get ( [ '/api/leaderboard' , '/leaderboard' ] , async ( req , res ) => {
291- const { range = 'realtime' , type, altcha } = req . query ;
292- let proc_type = parseInt ( type ) ;
291+ const { range = 'realtime' , altcha } = req . query ;
293292 if ( range !== 'realtime' && range !== 'daily' && range !== 'weekly' && range !== 'monthly' ) {
294293 return res . status ( 400 ) . json ( { success : false , error : 'Invalid range' } ) ;
295294 }
@@ -314,31 +313,34 @@ app.get(['/api/leaderboard', '/leaderboard'], async (req, res) => {
314313
315314 const [ board , expireTime ] = await getLeaderBoard ( range ) ;
316315 if ( range !== 'realtime' ) res . set ( 'QML-Cache-Expires' , `${ expireTime } ` ) ;
316+ if ( ! board || board . length === 0 ) {
317+ return res . json ( { success : false , list : [ ] } ) ;
318+ }
317319 let list = board . map ( ( array ) => { return { bvid : array [ 0 ] , count : array [ 1 ] } } ) ;
318320 // no type or type != 2: add backward capability
319- if ( ! proc_type || proc_type !== 2 ) {
320- await Promise . all ( list . map ( async ( item , index ) => {
321- try {
322- const conn = await fetch ( `https://api.bilibili.com/x/web-interface/view?bvid=${ item . bvid } ` ,
323- {
324- headers : {
325- "Origin" : "https://www.bilibili.com" ,
326- "Referer" : `https://www.bilibili.com/video/${ item . bvid } /` ,
327- 'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3' ,
328- }
329- } ) ;
330- const json = await conn . json ( ) ;
331- if ( json . code === 0 && json . data ?. title ) {
332- list [ index ] . title = json . data . title ;
333- } else {
334- list [ index ] . title = '未知标题' ;
335- }
336- } catch ( err ) {
337- console . error ( `获取标题失败 ${ item . bvid } :` , err ) ;
338- list [ index ] . title = '加载失败' ;
339- }
340- } ) ) ;
341- }
321+ // if (!proc_type || proc_type !== 2) {
322+ // await Promise.all(list.map(async (item, index) => {
323+ // try {
324+ // const conn = await fetch(`https://api.bilibili.com/x/web-interface/view?bvid=${item.bvid}`,
325+ // {
326+ // headers: {
327+ // "Origin": "https://www.bilibili.com",
328+ // "Referer": `https://www.bilibili.com/video/${item.bvid}/`,
329+ // 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
330+ // }
331+ // });
332+ // const json = await conn.json();
333+ // if (json.code === 0 && json.data?.title) {
334+ // list[index].title = json.data.title;
335+ // } else {
336+ // list[index].title = '未知标题';
337+ // }
338+ // } catch (err) {
339+ // console.error(`获取标题失败 ${item.bvid}:`, err);
340+ // list[index].title = '加载失败';
341+ // }
342+ // }));
343+ // }
342344 res . json ( { success : true , list : list } ) ;
343345 } catch ( error ) {
344346 res . status ( 500 ) . json ( { success : false , error : error . message } ) ;
0 commit comments