mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 05:04:56 +08:00
68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
import type { RouterData, ListContext, Options } from "../types.js";
|
|
import type { RouterType } from "../router.types.js";
|
|
import { get } from "../utils/getData.js";
|
|
|
|
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
|
const type = c.req.query("type") || "0";
|
|
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
|
const routeData: RouterData = {
|
|
name: "bilibili",
|
|
title: "哔哩哔哩",
|
|
type: "热门榜",
|
|
description: "你所热爱的,就是你的生活",
|
|
parameData: {
|
|
type: {
|
|
name: "排行榜分区",
|
|
type: {
|
|
0: "全站",
|
|
1: "动画",
|
|
3: "音乐",
|
|
4: "游戏",
|
|
5: "娱乐",
|
|
36: "科技",
|
|
119: "鬼畜",
|
|
129: "舞蹈",
|
|
155: "时尚",
|
|
160: "生活",
|
|
168: "国创相关",
|
|
188: "数码",
|
|
181: "影视",
|
|
},
|
|
},
|
|
},
|
|
link: "https://www.bilibili.com/v/popular/rank/all",
|
|
total: data?.length || 0,
|
|
updateTime,
|
|
fromCache,
|
|
data,
|
|
};
|
|
return routeData;
|
|
};
|
|
|
|
const getList = async (options: Options, noCache: boolean) => {
|
|
const { type } = options;
|
|
const url = `https://api.bilibili.com/x/web-interface/ranking/v2?rid=${type}`;
|
|
const result = await get({
|
|
url,
|
|
headers: {
|
|
Referer: `https://www.bilibili.com/ranking/all`,
|
|
},
|
|
noCache,
|
|
});
|
|
const list = result.data.data.list;
|
|
return {
|
|
fromCache: result.fromCache,
|
|
updateTime: result.updateTime,
|
|
data: list.map((v: RouterType["bilibili"]) => ({
|
|
id: v.bvid,
|
|
title: v.title,
|
|
desc: v.desc,
|
|
cover: v.pic.replace(/http:/, "https:"),
|
|
author: v.owner.name,
|
|
hot: v.stat.view,
|
|
url: v.short_link_v2 || `https://www.bilibili.com/video/${v.bvid}`,
|
|
mobileUrl: `https://m.bilibili.com/video/${v.bvid}`,
|
|
})),
|
|
};
|
|
};
|