mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 05:04:56 +08:00
feat: 掘金类目
This commit is contained in:
@@ -47,9 +47,21 @@ const getList = async (options: Options, noCache: boolean): Promise<RouterResTyp
|
|||||||
const result = await get({
|
const result = await get({
|
||||||
url,
|
url,
|
||||||
headers: {
|
headers: {
|
||||||
Referer: `https://www.bilibili.com/ranking/all`,
|
'Referer': 'https://www.bilibili.com/ranking/all',
|
||||||
"User-Agent":
|
'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',
|
||||||
"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',
|
||||||
},
|
},
|
||||||
noCache,
|
noCache,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,16 +1,55 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { ListContext, RouterData } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
import { get } from "../utils/getData.js";
|
||||||
|
|
||||||
// 类目接口
|
|
||||||
// https://api.juejin.cn/tag_api/v1/query_category_briefs
|
|
||||||
|
|
||||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
const headers = {
|
||||||
const listData = await getList(noCache);
|
'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<string, string> = {}
|
||||||
|
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 = {
|
const routeData: RouterData = {
|
||||||
name: "juejin",
|
name: "juejin",
|
||||||
title: "稀土掘金",
|
title: "稀土掘金",
|
||||||
type: "文章榜",
|
type: "文章榜",
|
||||||
|
params: {
|
||||||
|
type: {
|
||||||
|
name: "排行榜分区",
|
||||||
|
type: typeMaps,
|
||||||
|
},
|
||||||
|
},
|
||||||
link: "https://juejin.cn/hot/articles",
|
link: "https://juejin.cn/hot/articles",
|
||||||
total: listData.data?.length || 0,
|
total: listData.data?.length || 0,
|
||||||
...listData,
|
...listData,
|
||||||
@@ -18,9 +57,9 @@ export const handleRoute = async (_: undefined, noCache: boolean) => {
|
|||||||
return routeData;
|
return routeData;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getList = async (noCache: boolean) => {
|
const getList = async (noCache: boolean, type: number | string = 1) => {
|
||||||
const url = `https://api.juejin.cn/content_api/v1/content/article_rank?category_id=1&type=hot`;
|
const url = `https://api.juejin.cn/content_api/v1/content/article_rank?category_id=${type}&type=hot`;
|
||||||
const result = await get({ url, noCache });
|
const result = await get({ url, noCache, headers });
|
||||||
const list = result.data.data;
|
const list = result.data.data;
|
||||||
return {
|
return {
|
||||||
...result,
|
...result,
|
||||||
|
|||||||
Reference in New Issue
Block a user