mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 05:04:56 +08:00
🦄 refactor: 调整接口结构
This commit is contained in:
@@ -12,6 +12,7 @@ export type Config = {
|
||||
ALLOWED_HOST: string;
|
||||
USE_LOG_FILE: boolean;
|
||||
RSS_MODE: boolean;
|
||||
USE_PUPPETEER: boolean;
|
||||
};
|
||||
|
||||
// 验证并提取环境变量
|
||||
@@ -49,4 +50,5 @@ export const config: Config = {
|
||||
ALLOWED_HOST: getEnvVariable("ALLOWED_HOST") || "imsyy.top",
|
||||
USE_LOG_FILE: getBooleanEnvVariable("USE_LOG_FILE", true),
|
||||
RSS_MODE: getBooleanEnvVariable("RSS_MODE", false),
|
||||
USE_PUPPETEER: getBooleanEnvVariable("USE_PUPPETEER", false),
|
||||
};
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { serve } from "@hono/node-server";
|
||||
import { config } from "./config.js";
|
||||
import packageJson from "../package.json";
|
||||
import logger from "./utils/logger.js";
|
||||
import app from "./app.js";
|
||||
|
||||
@@ -11,8 +10,8 @@ const serveHotApi: (port?: number) => void = (port: number = config.PORT) => {
|
||||
fetch: app.fetch,
|
||||
port,
|
||||
});
|
||||
logger.info(`📦 Version: ${packageJson.version}`);
|
||||
logger.info(`🔥 DailyHot API 成功在端口 ${port} 上运行`);
|
||||
logger.info(`💻 Puppeteer: ${config.USE_PUPPETEER}`);
|
||||
logger.info(`🔗 Local: 👉 http://localhost:${port}`);
|
||||
return apiServer;
|
||||
} catch (error) {
|
||||
|
||||
@@ -12,7 +12,7 @@ const typeMap: Record<string, string> = {
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "hot";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "36kr",
|
||||
title: "36氪",
|
||||
@@ -24,10 +24,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://m.36kr.com/hot-list-m",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -59,8 +57,7 @@ const getList = async (options: Options, noCache: boolean): Promise<RouterResTyp
|
||||
const list =
|
||||
result.data.data[(listType as Record<string, keyof typeof result.data.data>)[type || "hot"]];
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["36kr"]) => {
|
||||
const item = v.templateMaterial;
|
||||
return {
|
||||
|
||||
@@ -5,16 +5,14 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "51cto",
|
||||
title: "51CTO",
|
||||
type: "推荐榜",
|
||||
link: "https://www.51cto.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -41,8 +39,7 @@ const getList = async (noCache: boolean): Promise<RouterResType> => {
|
||||
});
|
||||
const list = result.data.data.data.list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["51cto"]) => ({
|
||||
id: v.source_id,
|
||||
title: v.title,
|
||||
|
||||
@@ -5,7 +5,7 @@ import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "hot";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "52pojie",
|
||||
title: "吾爱破解",
|
||||
@@ -22,10 +22,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://www.52pojie.cn/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData?.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -47,8 +45,7 @@ const getList = async (options: Options, noCache: boolean): Promise<RouterResTyp
|
||||
};
|
||||
const list = await parseData();
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v, i) => ({
|
||||
id: v.guid || i,
|
||||
title: v.title || "",
|
||||
|
||||
@@ -27,7 +27,7 @@ const rangeMap: Record<string, string> = {
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "-1";
|
||||
const range = c.req.query("range") || "DAY";
|
||||
const { fromCache, data, updateTime } = await getList({ type, range }, noCache);
|
||||
const listData = await getList({ type, range }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "acfun",
|
||||
title: "AcFun",
|
||||
@@ -44,10 +44,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://www.acfun.cn/rank/list/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -64,8 +62,7 @@ const getList = async (options: Options, noCache: boolean): Promise<RouterResTyp
|
||||
});
|
||||
const list = result.data.rankList;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["acfun"]) => ({
|
||||
id: v.dougaId,
|
||||
title: v.contentTitle,
|
||||
|
||||
@@ -13,7 +13,7 @@ const typeMap: Record<string, string> = {
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "realtime";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "baidu",
|
||||
title: "百度",
|
||||
@@ -25,10 +25,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://top.baidu.com/board",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -49,8 +47,7 @@ const getList = async (options: Options, noCache: boolean): Promise<RouterResTyp
|
||||
const matchResult = result.data.match(pattern);
|
||||
const jsonObject = JSON.parse(matchResult[1]).cards[0].content;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: jsonObject.map((v: RouterType["baidu"]) => ({
|
||||
id: v.index,
|
||||
title: v.word,
|
||||
|
||||
@@ -22,7 +22,7 @@ const typeMap: Record<string, string> = {
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "0";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "bilibili",
|
||||
title: "哔哩哔哩",
|
||||
@@ -35,10 +35,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://www.bilibili.com/v/popular/rank/all",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -89,8 +87,7 @@ const getList = async (options: Options, noCache: boolean): Promise<RouterResTyp
|
||||
});
|
||||
const list = result.data.data.list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["bilibili"]) => ({
|
||||
id: v.bvid,
|
||||
title: v.title,
|
||||
|
||||
@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
|
||||
import { genHeaders } from "../utils/getToken/coolapk.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "coolapk",
|
||||
title: "酷安",
|
||||
type: "热榜",
|
||||
link: "https://www.coolapk.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -27,8 +25,7 @@ const getList = async (noCache: boolean) => {
|
||||
});
|
||||
const list = result.data.data;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["coolapk"]) => ({
|
||||
id: v.id,
|
||||
title: v.message,
|
||||
|
||||
@@ -4,17 +4,15 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "csdn",
|
||||
title: "CSDN",
|
||||
type: "排行榜",
|
||||
description: "专业开发者社区",
|
||||
link: "https://www.csdn.net/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -24,8 +22,7 @@ const getList = async (noCache: boolean): Promise<RouterResType> => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["csdn"]) => ({
|
||||
id: v.productId,
|
||||
title: v.articleTitle,
|
||||
|
||||
@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "douban-group",
|
||||
title: "豆瓣讨论",
|
||||
type: "讨论精选",
|
||||
link: "https://www.douban.com/group/explore",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -50,8 +48,7 @@ const getList = async (noCache: boolean) => {
|
||||
};
|
||||
});
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: listData,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -3,16 +3,14 @@ import { load } from "cheerio";
|
||||
import { get } from "../utils/getData.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "douban-movie",
|
||||
title: "豆瓣电影",
|
||||
type: "新片榜",
|
||||
link: "https://movie.douban.com/chart",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -58,8 +56,7 @@ const getList = async (noCache: boolean) => {
|
||||
};
|
||||
});
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: listData,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -4,17 +4,15 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "douyin",
|
||||
title: "抖音",
|
||||
type: "热榜",
|
||||
description: "实时上升热点",
|
||||
link: "https://www.douyin.com",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -47,8 +45,7 @@ const getList = async (noCache: boolean) => {
|
||||
});
|
||||
const list = result.data.data.word_list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["douyin"]) => ({
|
||||
id: v.sentence_id,
|
||||
title: v.word,
|
||||
|
||||
@@ -14,16 +14,14 @@ const mappings: Record<string, string> = {
|
||||
};
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "earthquake",
|
||||
title: "中国地震台",
|
||||
type: "地震速报",
|
||||
link: "https://news.ceic.ac.cn/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -35,8 +33,7 @@ const getList = async (noCache: boolean) => {
|
||||
const match = result.data.match(regex);
|
||||
const list = match && match[1] ? JSON.parse(match[1]) : [];
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["earthquake"]) => {
|
||||
const contentBuilder = [];
|
||||
const { NEW_DID, LOCATION_C, M } = v;
|
||||
|
||||
@@ -5,7 +5,7 @@ import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "1";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "genshin",
|
||||
title: "原神",
|
||||
@@ -21,10 +21,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://www.miyoushe.com/ys/home/28",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -35,8 +33,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["miyoushe"]) => {
|
||||
const data = v.post;
|
||||
return {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const sort = c.req.query("sort") || "featured";
|
||||
const { fromCache, data, updateTime } = await getList({ sort }, noCache);
|
||||
const listData = await getList({ sort }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "hellogithub",
|
||||
title: "HelloGitHub",
|
||||
@@ -21,10 +21,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://hellogithub.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -35,8 +33,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["hellogithub"]) => ({
|
||||
id: v.item_id,
|
||||
title: v.title,
|
||||
|
||||
@@ -8,7 +8,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
// 获取日期
|
||||
const day = c.req.query("day") || getCurrentDateTime(true).day;
|
||||
const month = c.req.query("month") || getCurrentDateTime(true).month;
|
||||
const { fromCache, data, updateTime } = await getList({ month, day }, noCache);
|
||||
const listData = await getList({ month, day }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "history",
|
||||
title: "历史上的今天",
|
||||
@@ -18,10 +18,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
day: "日期",
|
||||
},
|
||||
link: "https://baike.baidu.com/calendar",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -39,8 +37,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
});
|
||||
const list = monthStr ? result.data[monthStr][monthStr + dayStr] : [];
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["history"], index: number) => ({
|
||||
id: index,
|
||||
title: load(v.title).text().trim(),
|
||||
|
||||
@@ -5,7 +5,7 @@ import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "1";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "honkai",
|
||||
title: "崩坏3",
|
||||
@@ -21,10 +21,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://www.miyoushe.com/bh3/home/6",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -35,8 +33,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["miyoushe"]) => {
|
||||
const data = v.post;
|
||||
return {
|
||||
|
||||
@@ -12,7 +12,7 @@ const typeMap: Record<string, string> = {
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "hot";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "hostloc",
|
||||
title: "全球主机交流",
|
||||
@@ -24,10 +24,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://hostloc.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -49,8 +47,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
};
|
||||
const list = await parseData();
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v, i) => ({
|
||||
id: v.guid || i,
|
||||
title: v.title || "",
|
||||
|
||||
@@ -4,7 +4,7 @@ import { get } from "../utils/getData.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "1";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "hupu",
|
||||
title: "虎扑",
|
||||
@@ -22,10 +22,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://bbs.hupu.com/all-gambia",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -36,8 +34,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.topicThreads;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["hupu"]) => ({
|
||||
id: v.tid,
|
||||
title: v.title,
|
||||
|
||||
@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "huxiu",
|
||||
title: "虎嗅",
|
||||
type: "24小时",
|
||||
link: "https://www.huxiu.com/moment/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -38,8 +36,7 @@ const getList = async (noCache: boolean) => {
|
||||
const matchResult = result.data.match(pattern);
|
||||
const jsonObject = JSON.parse(matchResult[1]).moment.momentList.moment_list.datalist;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: jsonObject.map((v: RouterType["huxiu"]) => ({
|
||||
id: v.object_id,
|
||||
title: titleProcessing(v.content).title,
|
||||
|
||||
@@ -4,17 +4,15 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "ifanr",
|
||||
title: "爱范儿",
|
||||
type: "快讯",
|
||||
description: "15秒了解全球新鲜事",
|
||||
link: "https://www.ifanr.com/digest/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -24,8 +22,7 @@ const getList = async (noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.objects;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["ifanr"]) => ({
|
||||
id: v.id,
|
||||
title: v.post_title,
|
||||
|
||||
@@ -4,17 +4,15 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "ithome-xijiayi",
|
||||
title: "IT之家「喜加一」",
|
||||
type: "最新动态",
|
||||
description: "最新最全的「喜加一」游戏动态尽在这里!",
|
||||
link: "https://www.ithome.com/zt/xijiayi",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -51,8 +49,7 @@ const getList = async (noCache: boolean) => {
|
||||
};
|
||||
});
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: listData,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -4,17 +4,15 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "ithome",
|
||||
title: "IT之家",
|
||||
type: "热榜",
|
||||
description: "爱科技,爱这里 - 前沿科技新闻网站",
|
||||
link: "https://m.ithome.com/rankm/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -51,8 +49,7 @@ const getList = async (noCache: boolean) => {
|
||||
};
|
||||
});
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: listData,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -3,17 +3,15 @@ import { load } from "cheerio";
|
||||
import { get } from "../utils/getData.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "jianshu",
|
||||
title: "简书",
|
||||
type: "热门推荐",
|
||||
description: "一个优质的创作社区",
|
||||
link: "https://www.jianshu.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -52,8 +50,7 @@ const getList = async (noCache: boolean) => {
|
||||
};
|
||||
});
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: listData,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -3,16 +3,14 @@ import type { RouterType } from "../router.types.js";
|
||||
import { get } from "../utils/getData.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "juejin",
|
||||
title: "稀土掘金",
|
||||
type: "文章榜",
|
||||
link: "https://juejin.cn/hot/articles",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -22,8 +20,7 @@ const getList = async (noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["juejin"]) => ({
|
||||
id: v.content.content_id,
|
||||
title: v.content.title,
|
||||
|
||||
@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "lol",
|
||||
title: "英雄联盟",
|
||||
type: "更新公告",
|
||||
link: "https://lol.qq.com/gicp/news/423/2/1334/1.html",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -24,8 +22,7 @@ const getList = async (noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.result;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["lol"]) => ({
|
||||
id: v.iDocID,
|
||||
title: v.sTitle,
|
||||
|
||||
@@ -25,7 +25,7 @@ const typeMap: Record<string, string> = {
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const game = c.req.query("game") || "1";
|
||||
const type = c.req.query("type") || "1";
|
||||
const { fromCache, data, updateTime } = await getList({ game, type }, noCache);
|
||||
const listData = await getList({ game, type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "miyoushe",
|
||||
title: `米游社 · ${gameMap[game]}`,
|
||||
@@ -41,10 +41,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://www.miyoushe.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -55,8 +53,7 @@ const getList = async (options: Options, noCache: boolean): Promise<RouterResTyp
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["miyoushe"]) => {
|
||||
const data = v.post;
|
||||
return {
|
||||
|
||||
@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "netease-news",
|
||||
title: "网易新闻",
|
||||
type: "热点榜",
|
||||
link: "https://m.163.com/hot",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -23,8 +21,7 @@ const getList = async (noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["netease-news"]) => ({
|
||||
id: v.docid,
|
||||
title: v.title,
|
||||
|
||||
@@ -4,17 +4,15 @@ import { post } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "ngabbs",
|
||||
title: "NGA",
|
||||
type: "论坛热帖",
|
||||
description: "精英玩家俱乐部",
|
||||
link: "https://ngabbs.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -42,8 +40,7 @@ const getList = async (noCache: boolean) => {
|
||||
});
|
||||
const list = result.data.result[0];
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["ngabbs"]) => ({
|
||||
id: v.tid,
|
||||
title: v.subject,
|
||||
|
||||
@@ -5,7 +5,7 @@ import { parseStringPromise } from "xml2js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "nodeseek",
|
||||
title: "NodeSeek",
|
||||
@@ -19,10 +19,8 @@ export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://www.nodeseek.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -33,8 +31,7 @@ const getList = async (noCache: boolean) => {
|
||||
const rssData = await parseStringPromise(result.data);
|
||||
const list = rssData.rss.channel[0].item;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["nodeseek"]) => ({
|
||||
id: v.guid[0]._,
|
||||
title: v.title[0],
|
||||
|
||||
@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "qq-news",
|
||||
title: "腾讯新闻",
|
||||
type: "热点榜",
|
||||
link: "https://news.qq.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -23,8 +21,7 @@ const getList = async (noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.idlist[0].newslist.slice(1);
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["qq-news"]) => ({
|
||||
id: v.id,
|
||||
title: v.title,
|
||||
|
||||
@@ -64,7 +64,7 @@ const listType = {
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "1";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "sina-news",
|
||||
title: "新浪新闻",
|
||||
@@ -76,10 +76,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://sinanews.sina.cn/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -122,8 +120,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = parseData(result.data).data;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["sina-news"]) => ({
|
||||
id: v.id,
|
||||
title: v.title,
|
||||
|
||||
@@ -5,7 +5,7 @@ import { get } from "../utils/getData.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "1";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "sina",
|
||||
title: "新浪网",
|
||||
@@ -28,10 +28,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://sinanews.sina.cn/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -42,8 +40,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.hotList;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["sina"]) => {
|
||||
const base = v.base;
|
||||
const info = v.info;
|
||||
|
||||
@@ -5,7 +5,7 @@ import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "热门文章";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "sspai",
|
||||
title: "少数派",
|
||||
@@ -17,10 +17,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://sspai.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -31,8 +29,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["sspai"]) => ({
|
||||
id: v.id,
|
||||
title: v.title,
|
||||
|
||||
@@ -5,7 +5,7 @@ import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "1";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "starrail",
|
||||
title: "崩坏:星穹铁道",
|
||||
@@ -21,10 +21,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://www.miyoushe.com/sr/home/53",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -35,8 +33,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["miyoushe"]) => {
|
||||
const data = v.post;
|
||||
return {
|
||||
|
||||
@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "thepaper",
|
||||
title: "澎湃新闻",
|
||||
type: "热榜",
|
||||
link: "https://www.thepaper.cn/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -23,8 +21,7 @@ const getList = async (noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.hotNews;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["thepaper"]) => ({
|
||||
id: v.contId,
|
||||
title: v.name,
|
||||
|
||||
@@ -4,17 +4,15 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "tieba",
|
||||
title: "百度贴吧",
|
||||
type: "热议榜",
|
||||
description: "全球领先的中文社区",
|
||||
link: "https://tieba.baidu.com/hottopic/browse/topicList",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -24,8 +22,7 @@ const getList = async (noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.bang_topic.topic_list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["tieba"]) => ({
|
||||
id: v.topic_id,
|
||||
title: v.topic_name,
|
||||
|
||||
@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "toutiao",
|
||||
title: "今日头条",
|
||||
type: "热榜",
|
||||
link: "https://www.toutiao.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -23,8 +21,7 @@ const getList = async (noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["toutiao"]) => ({
|
||||
id: v.ClusterIdStr,
|
||||
title: v.Title,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { get } from "../utils/getData.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "hot";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "v2ex",
|
||||
title: "V2EX",
|
||||
@@ -19,10 +19,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://www.v2ex.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -33,8 +31,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["v2ex"]) => ({
|
||||
id: v.id,
|
||||
title: v.title,
|
||||
|
||||
@@ -5,11 +5,11 @@ import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const province = c.req.query("province") || "";
|
||||
const { fromCache, data, type, updateTime } = await getList({ province }, noCache);
|
||||
const listData = await getList({ province }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "weatheralarm",
|
||||
title: "中央气象台",
|
||||
type: type || "全国气象预警",
|
||||
type: `${province || "全国"}气象预警`,
|
||||
params: {
|
||||
province: {
|
||||
name: "预警区域",
|
||||
@@ -17,10 +17,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "http://nmc.cn/publish/alarm.html",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -31,9 +29,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.page.list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
type: province + "气象预警",
|
||||
...result,
|
||||
data: list.map((v: RouterType["weatheralarm"]) => ({
|
||||
id: v.alertid,
|
||||
title: v.title,
|
||||
|
||||
@@ -4,17 +4,15 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "weibo",
|
||||
title: "微博",
|
||||
type: "热搜榜",
|
||||
description: "实时热点,每分钟更新一次",
|
||||
link: "https://s.weibo.com/top/summary/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -24,8 +22,7 @@ const getList = async (noCache: boolean) => {
|
||||
const result = await get({ url, noCache, ttl: 60 });
|
||||
const list = result.data.data.realtime;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["weibo"]) => {
|
||||
const key = v.word_scheme ? v.word_scheme : `#${v.word}`;
|
||||
return {
|
||||
|
||||
@@ -5,16 +5,14 @@ import getWereadID from "../utils/getToken/weread.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "weread",
|
||||
title: "微信读书",
|
||||
type: "飙升榜",
|
||||
link: "https://weread.qq.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -31,8 +29,7 @@ const getList = async (noCache: boolean) => {
|
||||
});
|
||||
const list = result.data.books;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["weread"]) => {
|
||||
const data = v.bookInfo;
|
||||
return {
|
||||
|
||||
@@ -3,17 +3,15 @@ import type { RouterType } from "../router.types.js";
|
||||
import { get } from "../utils/getData.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "zhihu-daily",
|
||||
title: "知乎日报",
|
||||
type: "推荐榜",
|
||||
description: "每天三次,每次七分钟",
|
||||
link: "https://daily.zhihu.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -30,8 +28,7 @@ const getList = async (noCache: boolean) => {
|
||||
});
|
||||
const list = result.data.stories.filter((el: RouterType["zhihu-daily"]) => el.type === 0);
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["zhihu-daily"]) => ({
|
||||
id: v.id,
|
||||
title: v.title,
|
||||
|
||||
@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "zhihu",
|
||||
title: "知乎",
|
||||
type: "热榜",
|
||||
link: "https://www.zhihu.com/hot",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -23,8 +21,7 @@ const getList = async (noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["zhihu"]) => {
|
||||
const data = v.target;
|
||||
return {
|
||||
|
||||
3
src/types.d.ts
vendored
3
src/types.d.ts
vendored
@@ -18,9 +18,10 @@ export interface ListItem {
|
||||
|
||||
// 路由接口数据
|
||||
export interface RouterResType {
|
||||
updateTime: string;
|
||||
updateTime: string | number;
|
||||
fromCache: boolean;
|
||||
data: ListItem[];
|
||||
message?: string;
|
||||
}
|
||||
|
||||
// 路由数据
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Get, Post, Web } from "../types.ts";
|
||||
import type { Get, Post, Web } from "../types.js";
|
||||
import type { Page } from "puppeteer";
|
||||
import { config } from "../config.js";
|
||||
import { getCache, setCache, delCache } from "./cache.js";
|
||||
import { Cluster } from "puppeteer-cluster";
|
||||
@@ -12,24 +13,50 @@ const request = axios.create({
|
||||
withCredentials: true,
|
||||
});
|
||||
|
||||
// puppeteer-cluster
|
||||
export const createCluster = async () => {
|
||||
return await Cluster.launch({
|
||||
concurrency: Cluster.CONCURRENCY_BROWSER,
|
||||
maxConcurrency: 5,
|
||||
// puppeteer
|
||||
puppeteerOptions: {
|
||||
headless: true,
|
||||
args: ["--no-sandbox", "--disable-setuid-sandbox"],
|
||||
},
|
||||
});
|
||||
// Puppeteer Cluster
|
||||
let cluster: Cluster | null = null;
|
||||
|
||||
/**
|
||||
* 创建 Puppeteer Cluster
|
||||
* @returns {Promise<Cluster|null>} Puppeteer Cluster
|
||||
*/
|
||||
export const createCluster = async (): Promise<Cluster | null> => {
|
||||
if (cluster) return cluster;
|
||||
try {
|
||||
cluster = await Cluster.launch({
|
||||
concurrency: Cluster.CONCURRENCY_BROWSER,
|
||||
maxConcurrency: 5,
|
||||
puppeteerOptions: {
|
||||
headless: true,
|
||||
args: [
|
||||
"--no-sandbox",
|
||||
"--disable-gpu",
|
||||
"--disable-setuid-sandbox",
|
||||
"--disable-dev-shm-usage",
|
||||
],
|
||||
},
|
||||
});
|
||||
logger.info("Puppeteer Cluster 已成功初始化");
|
||||
} catch (error) {
|
||||
logger.warn("启动 Puppeteer Cluster 失败,可能是没有 Chromium 安装", error);
|
||||
cluster = null;
|
||||
}
|
||||
return cluster;
|
||||
};
|
||||
|
||||
// Cluster
|
||||
const cluster = await createCluster();
|
||||
|
||||
// Cluster configuration
|
||||
cluster.task(async ({ page, data: { url, userAgent } }) => {
|
||||
/**
|
||||
* 处理任务
|
||||
* @param page 页面
|
||||
* @param data 数据
|
||||
* @returns
|
||||
*/
|
||||
const taskHandler = async ({
|
||||
page,
|
||||
data: { url, userAgent },
|
||||
}: {
|
||||
page: Page;
|
||||
data: { url: string; userAgent?: string };
|
||||
}): Promise<string> => {
|
||||
// 用户代理
|
||||
if (userAgent) await page.setUserAgent(userAgent);
|
||||
// 请求拦截
|
||||
@@ -45,9 +72,9 @@ cluster.task(async ({ page, data: { url, userAgent } }) => {
|
||||
});
|
||||
// 加载页面
|
||||
await page.goto(url, { waitUntil: "networkidle0", timeout: config.REQUEST_TIMEOUT });
|
||||
const pageContent = await page.content();
|
||||
return pageContent;
|
||||
});
|
||||
// 返回页面内容
|
||||
return page.content();
|
||||
};
|
||||
|
||||
// 请求拦截
|
||||
request.interceptors.request.use(
|
||||
@@ -137,12 +164,25 @@ export const post = async (options: Post) => {
|
||||
}
|
||||
};
|
||||
|
||||
// puppeteer
|
||||
// WEB - Puppeteer
|
||||
export const web = async (options: Web) => {
|
||||
const { url, noCache, ttl = config.CACHE_TTL, userAgent } = options;
|
||||
logger.info("使用 Puppeteer 发起页面请求", options);
|
||||
if (config.USE_PUPPETEER === false) {
|
||||
return {
|
||||
fromCache: false,
|
||||
data: [],
|
||||
message: "Puppeteer is not enabled, please set USE_PUPPETEER=true",
|
||||
updateTime: 0,
|
||||
};
|
||||
}
|
||||
// 初始化 Cluster
|
||||
const clusterInstance = await createCluster();
|
||||
if (!clusterInstance) {
|
||||
logger.error("Cluster 初始化失败,无法继续");
|
||||
throw new Error("Cluster 初始化失败");
|
||||
}
|
||||
try {
|
||||
if (!cluster) throw new Error("Cluster is not initialized");
|
||||
// 检查缓存
|
||||
if (noCache) {
|
||||
delCache(url);
|
||||
@@ -155,7 +195,7 @@ export const web = async (options: Web) => {
|
||||
}
|
||||
// 缓存不存在时使用 Puppeteer 请求页面
|
||||
logger.info("启动浏览器请求页面", { url });
|
||||
const pageContent = await cluster.execute({ url, userAgent });
|
||||
const pageContent = await clusterInstance.execute({ url, userAgent }, taskHandler);
|
||||
// 存储新获取的数据到缓存
|
||||
const updateTime = new Date().toISOString();
|
||||
setCache(url, { data: pageContent, updateTime }, ttl);
|
||||
@@ -167,3 +207,17 @@ export const web = async (options: Web) => {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 关闭 Cluster
|
||||
*/
|
||||
export const closeCluster = async () => {
|
||||
if (cluster) {
|
||||
try {
|
||||
await cluster.close();
|
||||
logger.info("Puppeteer Cluster 已成功关闭");
|
||||
} catch (error) {
|
||||
logger.error("关闭 Puppeteer Cluster 时出错", error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -25,8 +25,8 @@ export const parseRSS = async (rssContent: string) => {
|
||||
try {
|
||||
new URL(url);
|
||||
return true;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user