From 94ba2478d18d24c21ac4f0e22873f33c70ac57b3 Mon Sep 17 00:00:00 2001 From: helti Date: Fri, 7 Feb 2025 23:00:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8E=98=E9=87=91=E7=B1=BB=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/bilibili.ts | 18 +++++++++++--- src/routes/juejin.ts | 55 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 62 insertions(+), 11 deletions(-) diff --git a/src/routes/bilibili.ts b/src/routes/bilibili.ts index 0d773f0..4744fbc 100644 --- a/src/routes/bilibili.ts +++ b/src/routes/bilibili.ts @@ -47,9 +47,21 @@ const getList = async (options: Options, noCache: boolean): Promise { - const listData = await getList(noCache); +const headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36', + 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', + 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8', + 'Accept-Encoding': 'gzip, deflate, br', + 'Cache-Control': 'no-cache', + 'Connection': 'keep-alive', + 'Sec-Ch-Ua': '"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"', + 'Sec-Ch-Ua-Mobile': '?0', + 'Sec-Ch-Ua-Platform': '"Windows"', + 'Sec-Fetch-Dest': 'document', + 'Sec-Fetch-Mode': 'navigate', + 'Sec-Fetch-Site': 'same-origin', + 'Sec-Fetch-User': '?1', + 'Upgrade-Insecure-Requests': '1', +} + +const category_url = 'https://api.juejin.cn/tag_api/v1/query_category_briefs' +const getCategory = async()=>{ + const res = await get({ + url: category_url, + headers + }) + const data = res?.data?.data || [] + const typeObj: Record = {} + typeObj['1'] = '综合' + data.forEach((c: { category_id: string; category_name: string }) => { + typeObj[c.category_id] = c.category_name + }) + + return typeObj +} + +export const handleRoute = async (c: ListContext, noCache: boolean) => { + const type = c.req.query("type") || 1; + const listData = await getList(noCache, type); + const typeMaps = await getCategory() const routeData: RouterData = { name: "juejin", title: "稀土掘金", type: "文章榜", + params: { + type: { + name: "排行榜分区", + type: typeMaps, + }, + }, link: "https://juejin.cn/hot/articles", total: listData.data?.length || 0, ...listData, @@ -18,9 +57,9 @@ export const handleRoute = async (_: undefined, noCache: boolean) => { return routeData; }; -const getList = async (noCache: boolean) => { - const url = `https://api.juejin.cn/content_api/v1/content/article_rank?category_id=1&type=hot`; - const result = await get({ url, noCache }); +const getList = async (noCache: boolean, type: number | string = 1) => { + const url = `https://api.juejin.cn/content_api/v1/content/article_rank?category_id=${type}&type=hot`; + const result = await get({ url, noCache, headers }); const list = result.data.data; return { ...result,