mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 13:14:55 +08:00
✨ feat: 新增 历史上的今天
This commit is contained in:
3
.github/workflows/npm.yml
vendored
3
.github/workflows/npm.yml
vendored
@@ -6,8 +6,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish-npm:
|
publish-npm:
|
||||||
runs-on:
|
runs-on: ubuntu-latest
|
||||||
ubuntu-latest
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [20]
|
node-version: [20]
|
||||||
|
|||||||
@@ -66,6 +66,7 @@
|
|||||||
| HelloGitHub | Trending | hellogithub | 🟢 |
|
| HelloGitHub | Trending | hellogithub | 🟢 |
|
||||||
| 中央气象台 | 全国气象预警 | weatheralarm | 🟢 |
|
| 中央气象台 | 全国气象预警 | weatheralarm | 🟢 |
|
||||||
| 中国地震台 | 地震速报 | earthquake | 🟢 |
|
| 中国地震台 | 地震速报 | earthquake | 🟢 |
|
||||||
|
| 历史上的今天 | 月-日 | history | 🟢 |
|
||||||
|
|
||||||
## ⚙️ 使用
|
## ⚙️ 使用
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dailyhot-api",
|
"name": "dailyhot-api",
|
||||||
"version": "2.0.1",
|
"version": "2.0.2",
|
||||||
"description": "An Api on Today's Hot list",
|
"description": "An Api on Today's Hot list",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"API",
|
"API",
|
||||||
@@ -47,8 +47,6 @@
|
|||||||
"hono": "^4.4.3",
|
"hono": "^4.4.3",
|
||||||
"md5": "^2.3.0",
|
"md5": "^2.3.0",
|
||||||
"node-cache": "^5.1.2",
|
"node-cache": "^5.1.2",
|
||||||
"puppeteer": "^22.10.0",
|
|
||||||
"puppeteer-cluster": "^0.24.0",
|
|
||||||
"rss-parser": "^3.13.0",
|
"rss-parser": "^3.13.0",
|
||||||
"winston": "^3.13.0"
|
"winston": "^3.13.0"
|
||||||
},
|
},
|
||||||
|
|||||||
801
pnpm-lock.yaml
generated
801
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData, ListContext, Options } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { post } from "../utils/getData.js";
|
import { post } from "../utils/getData.js";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||||
const type = c.req.query("type") || "hot";
|
const type = c.req.query("type") || "hot";
|
||||||
@@ -10,7 +10,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
|||||||
name: "36kr",
|
name: "36kr",
|
||||||
title: "36氪",
|
title: "36氪",
|
||||||
type: "热榜",
|
type: "热榜",
|
||||||
parameData: {
|
parame: {
|
||||||
type: {
|
type: {
|
||||||
name: "热榜分类",
|
name: "热榜分类",
|
||||||
type: {
|
type: {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { RouterData } from "../types.js";
|
|||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { getToken, sign } from "../utils/getToken/51cto.js";
|
import { getToken, sign } from "../utils/getToken/51cto.js";
|
||||||
import { get } from "../utils/getData.js";
|
import { get } from "../utils/getData.js";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
const { fromCache, data, updateTime } = await getList(noCache);
|
const { fromCache, data, updateTime } = await getList(noCache);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { RouterData, ListContext, Options } from "../types.js";
|
|||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { web } from "../utils/getData.js";
|
import { web } from "../utils/getData.js";
|
||||||
import { extractRss, parseRSS } from "../utils/parseRSS.js";
|
import { extractRss, parseRSS } from "../utils/parseRSS.js";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||||
const type = c.req.query("type") || "hot";
|
const type = c.req.query("type") || "hot";
|
||||||
@@ -11,7 +11,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
|||||||
name: "52pojie",
|
name: "52pojie",
|
||||||
title: "吾爱破解",
|
title: "吾爱破解",
|
||||||
type: "榜单",
|
type: "榜单",
|
||||||
parameData: {
|
parame: {
|
||||||
type: {
|
type: {
|
||||||
name: "榜单分类",
|
name: "榜单分类",
|
||||||
type: {
|
type: {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData, ListContext, Options } 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";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||||
const type = c.req.query("type") || "-1";
|
const type = c.req.query("type") || "-1";
|
||||||
@@ -12,7 +12,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
|||||||
title: "AcFun",
|
title: "AcFun",
|
||||||
type: "排行榜",
|
type: "排行榜",
|
||||||
description: "AcFun是一家弹幕视频网站,致力于为每一个人带来欢乐。",
|
description: "AcFun是一家弹幕视频网站,致力于为每一个人带来欢乐。",
|
||||||
parameData: {
|
parame: {
|
||||||
type: {
|
type: {
|
||||||
name: "频道",
|
name: "频道",
|
||||||
type: {
|
type: {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
|||||||
name: "baidu",
|
name: "baidu",
|
||||||
title: "百度",
|
title: "百度",
|
||||||
type: "热搜榜",
|
type: "热搜榜",
|
||||||
parameData: {
|
parame: {
|
||||||
type: {
|
type: {
|
||||||
name: "热搜类别",
|
name: "热搜类别",
|
||||||
type: {
|
type: {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { RouterData, ListContext, Options } 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";
|
||||||
import getBiliWbi from "../utils/getToken/bilibili.js";
|
import getBiliWbi from "../utils/getToken/bilibili.js";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||||
const type = c.req.query("type") || "0";
|
const type = c.req.query("type") || "0";
|
||||||
@@ -12,7 +12,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
|||||||
title: "哔哩哔哩",
|
title: "哔哩哔哩",
|
||||||
type: "热门榜",
|
type: "热门榜",
|
||||||
description: "你所热爱的,就是你的生活",
|
description: "你所热爱的,就是你的生活",
|
||||||
parameData: {
|
parame: {
|
||||||
type: {
|
type: {
|
||||||
name: "排行榜分区",
|
name: "排行榜分区",
|
||||||
type: {
|
type: {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { 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";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
const { fromCache, data, updateTime } = await getList(noCache);
|
const { fromCache, data, updateTime } = await getList(noCache);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData, ListContext, Options } 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";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
const mappings = {
|
const mappings = {
|
||||||
O_TIME: "发震时刻(UTC+8)",
|
O_TIME: "发震时刻(UTC+8)",
|
||||||
@@ -33,7 +33,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
|||||||
name: "earthquake",
|
name: "earthquake",
|
||||||
title: "中国地震台",
|
title: "中国地震台",
|
||||||
type: "地震速报",
|
type: "地震速报",
|
||||||
parameData: {
|
parame: {
|
||||||
type: {
|
type: {
|
||||||
name: "速报分类",
|
name: "速报分类",
|
||||||
type: {
|
type: {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData, ListContext, Options } 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";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||||
const type = c.req.query("type") || "1";
|
const type = c.req.query("type") || "1";
|
||||||
@@ -10,7 +10,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
|||||||
name: "genshin",
|
name: "genshin",
|
||||||
title: "原神",
|
title: "原神",
|
||||||
type: "最新动态",
|
type: "最新动态",
|
||||||
parameData: {
|
parame: {
|
||||||
type: {
|
type: {
|
||||||
name: "榜单分类",
|
name: "榜单分类",
|
||||||
type: {
|
type: {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData, ListContext, Options } 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";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||||
const sort = c.req.query("sort") || "featured";
|
const sort = c.req.query("sort") || "featured";
|
||||||
@@ -11,7 +11,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
|||||||
title: "HelloGitHub",
|
title: "HelloGitHub",
|
||||||
type: "热门仓库",
|
type: "热门仓库",
|
||||||
description: "分享 GitHub 上有趣、入门级的开源项目",
|
description: "分享 GitHub 上有趣、入门级的开源项目",
|
||||||
parameData: {
|
parame: {
|
||||||
sort: {
|
sort: {
|
||||||
name: "排行榜分区",
|
name: "排行榜分区",
|
||||||
type: {
|
type: {
|
||||||
|
|||||||
51
src/routes/history.ts
Normal file
51
src/routes/history.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import type { RouterData, ListContext, Options } from "../types.js";
|
||||||
|
import { load } from "cheerio";
|
||||||
|
import { get } from "../utils/getData.js";
|
||||||
|
import { getCurrentDateTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
|
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||||
|
// 获取日期
|
||||||
|
const day = c.req.query("day") || getCurrentDateTime().day;
|
||||||
|
const month = c.req.query("month") || getCurrentDateTime().month;
|
||||||
|
const { fromCache, data, updateTime } = await getList({ month, day }, noCache);
|
||||||
|
const routeData: RouterData = {
|
||||||
|
name: "history",
|
||||||
|
title: "历史上的今天",
|
||||||
|
type: `${month}-${day}`,
|
||||||
|
parame: {
|
||||||
|
month: "月份",
|
||||||
|
day: "日期",
|
||||||
|
},
|
||||||
|
link: "https://www.lssjt.com/",
|
||||||
|
total: data?.length || 0,
|
||||||
|
updateTime,
|
||||||
|
fromCache,
|
||||||
|
data,
|
||||||
|
};
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
const getList = async (options: Options, noCache: boolean) => {
|
||||||
|
const { month, day } = options;
|
||||||
|
const url = `https://www.lssjt.com/${month}/${day}/`;
|
||||||
|
const result = await get({ url, noCache });
|
||||||
|
const $ = load(result.data);
|
||||||
|
const listDom = $("li.circler");
|
||||||
|
const listData = listDom.toArray().map((item, index) => {
|
||||||
|
const dom = $(item);
|
||||||
|
const href = dom.find("a").attr("href");
|
||||||
|
return {
|
||||||
|
id: index,
|
||||||
|
title: dom.find("a.txt").text().trim() || dom.find("a").attr("title"),
|
||||||
|
cover: dom.find("img").attr("data-original"),
|
||||||
|
timestamp: dom.find("div.text span").text().trim() || dom.find("div.t span").text().trim(),
|
||||||
|
hot: null,
|
||||||
|
url: href || undefined,
|
||||||
|
mobileUrl: href || undefined,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
fromCache: result.fromCache,
|
||||||
|
updateTime: result.updateTime,
|
||||||
|
data: listData,
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData, ListContext, Options } 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";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||||
const type = c.req.query("type") || "1";
|
const type = c.req.query("type") || "1";
|
||||||
@@ -10,7 +10,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
|||||||
name: "honkai",
|
name: "honkai",
|
||||||
title: "崩坏3",
|
title: "崩坏3",
|
||||||
type: "最新动态",
|
type: "最新动态",
|
||||||
parameData: {
|
parame: {
|
||||||
type: {
|
type: {
|
||||||
name: "榜单分类",
|
name: "榜单分类",
|
||||||
type: {
|
type: {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { RouterData, ListContext, Options } from "../types.js";
|
|||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { web } from "../utils/getData.js";
|
import { web } from "../utils/getData.js";
|
||||||
import { extractRss, parseRSS } from "../utils/parseRSS.js";
|
import { extractRss, parseRSS } from "../utils/parseRSS.js";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||||
const type = c.req.query("type") || "hot";
|
const type = c.req.query("type") || "hot";
|
||||||
@@ -11,7 +11,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
|||||||
name: "hostloc",
|
name: "hostloc",
|
||||||
title: "全球主机交流",
|
title: "全球主机交流",
|
||||||
type: "榜单",
|
type: "榜单",
|
||||||
parameData: {
|
parame: {
|
||||||
type: {
|
type: {
|
||||||
name: "榜单分类",
|
name: "榜单分类",
|
||||||
type: {
|
type: {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { 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";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
const { fromCache, data, updateTime } = await getList(noCache);
|
const { fromCache, data, updateTime } = await getList(noCache);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { 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";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
const { fromCache, data, updateTime } = await getList(noCache);
|
const { fromCache, data, updateTime } = await getList(noCache);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { RouterData } from "../types.js";
|
||||||
import { load } from "cheerio";
|
import { load } from "cheerio";
|
||||||
import { get } from "../utils/getData.js";
|
import { get } from "../utils/getData.js";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
const { fromCache, data, updateTime } = await getList(noCache);
|
const { fromCache, data, updateTime } = await getList(noCache);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { 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";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
const { fromCache, data, updateTime } = await getList(noCache);
|
const { fromCache, data, updateTime } = await getList(noCache);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { 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";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
const { fromCache, data, updateTime } = await getList(noCache);
|
const { fromCache, data, updateTime } = await getList(noCache);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { RouterData } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { post } from "../utils/getData.js";
|
import { post } from "../utils/getData.js";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
const { fromCache, data, updateTime } = await getList(noCache);
|
const { fromCache, data, updateTime } = await getList(noCache);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { 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";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
const { fromCache, data, updateTime } = await getList(noCache);
|
const { fromCache, data, updateTime } = await getList(noCache);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData, ListContext, Options } 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";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||||
const type = c.req.query("type") || "热门文章";
|
const type = c.req.query("type") || "热门文章";
|
||||||
@@ -10,7 +10,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
|||||||
name: "sspai",
|
name: "sspai",
|
||||||
title: "少数派",
|
title: "少数派",
|
||||||
type: "热榜",
|
type: "热榜",
|
||||||
parameData: {
|
parame: {
|
||||||
type: {
|
type: {
|
||||||
name: "分类",
|
name: "分类",
|
||||||
type: ["热门文章", "应用推荐", "生活方式", "效率技巧", "少数派播客"],
|
type: ["热门文章", "应用推荐", "生活方式", "效率技巧", "少数派播客"],
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData, ListContext, Options } 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";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||||
const type = c.req.query("type") || "1";
|
const type = c.req.query("type") || "1";
|
||||||
@@ -10,7 +10,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
|||||||
name: "starrail",
|
name: "starrail",
|
||||||
title: "崩坏:星穹铁道",
|
title: "崩坏:星穹铁道",
|
||||||
type: "最新动态",
|
type: "最新动态",
|
||||||
parameData: {
|
parame: {
|
||||||
type: {
|
type: {
|
||||||
name: "榜单分类",
|
name: "榜单分类",
|
||||||
type: {
|
type: {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { 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";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
const { fromCache, data, updateTime } = await getList(noCache);
|
const { fromCache, data, updateTime } = await getList(noCache);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { 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";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
const { fromCache, data, updateTime } = await getList(noCache);
|
const { fromCache, data, updateTime } = await getList(noCache);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { 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";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
const { fromCache, data, updateTime } = await getList(noCache);
|
const { fromCache, data, updateTime } = await getList(noCache);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
|||||||
name: "v2ex",
|
name: "v2ex",
|
||||||
title: "V2EX",
|
title: "V2EX",
|
||||||
type: "主题榜",
|
type: "主题榜",
|
||||||
parameData: {
|
parame: {
|
||||||
type: {
|
type: {
|
||||||
name: "榜单分类",
|
name: "榜单分类",
|
||||||
type: {
|
type: {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData, ListContext, Options } 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";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||||
const province = c.req.query("province") || "";
|
const province = c.req.query("province") || "";
|
||||||
@@ -10,7 +10,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
|||||||
name: "weatheralarm",
|
name: "weatheralarm",
|
||||||
title: "中央气象台",
|
title: "中央气象台",
|
||||||
type: type || "全国气象预警",
|
type: type || "全国气象预警",
|
||||||
parameData: {
|
parame: {
|
||||||
province: {
|
province: {
|
||||||
name: "预警区域",
|
name: "预警区域",
|
||||||
value: "省份名称( 例如:广东省 )",
|
value: "省份名称( 例如:广东省 )",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { 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";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
const { fromCache, data, updateTime } = await getList(noCache);
|
const { fromCache, data, updateTime } = await getList(noCache);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { 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";
|
||||||
import getWereadID from "../utils/getToken/weread.js";
|
import getWereadID from "../utils/getToken/weread.js";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
const { fromCache, data, updateTime } = await getList(noCache);
|
const { fromCache, data, updateTime } = await getList(noCache);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { 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";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
const { fromCache, data, updateTime } = await getList(noCache);
|
const { fromCache, data, updateTime } = await getList(noCache);
|
||||||
|
|||||||
6
src/types.d.ts
vendored
6
src/types.d.ts
vendored
@@ -22,7 +22,7 @@ export type RouterData = {
|
|||||||
title: string;
|
title: string;
|
||||||
type: string;
|
type: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
parameData?: Record<string, string | object>;
|
parame?: Record<string, string | object>;
|
||||||
total: number;
|
total: number;
|
||||||
link?: string;
|
link?: string;
|
||||||
updateTime: string;
|
updateTime: string;
|
||||||
@@ -61,5 +61,5 @@ export type Web = {
|
|||||||
|
|
||||||
// 参数类型
|
// 参数类型
|
||||||
export type Options = {
|
export type Options = {
|
||||||
[key: string]: string | undefined;
|
[key: string]: string | number | undefined;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { Get, Post, Web } from "../types.ts";
|
import type { Get, Post, Web } from "../types.ts";
|
||||||
import { config } from "../config.js";
|
import { config } from "../config.js";
|
||||||
import { getCache, setCache, delCache } from "./cache.js";
|
import { getCache, setCache, delCache } from "./cache.js";
|
||||||
import { Cluster } from "puppeteer-cluster";
|
// import { Cluster } from "puppeteer-cluster";
|
||||||
import logger from "./logger.js";
|
import logger from "./logger.js";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
@@ -13,25 +13,26 @@ const request = axios.create({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// puppeteer-cluster
|
// puppeteer-cluster
|
||||||
export const createCluster = async () => {
|
// export const createCluster = async () => {
|
||||||
return await Cluster.launch({
|
// return await Cluster.launch({
|
||||||
concurrency: Cluster.CONCURRENCY_BROWSER,
|
// concurrency: Cluster.CONCURRENCY_BROWSER,
|
||||||
maxConcurrency: 5,
|
// maxConcurrency: 5,
|
||||||
});
|
// });
|
||||||
};
|
// };
|
||||||
|
|
||||||
// Cluster
|
// Cluster
|
||||||
const cluster = await createCluster();
|
// const cluster = await createCluster();
|
||||||
|
const cluster = null;
|
||||||
|
|
||||||
// Cluster configuration
|
// Cluster configuration
|
||||||
cluster.task(async ({ page, data: { url, userAgent } }) => {
|
// cluster.task(async ({ page, data: { url, userAgent } }) => {
|
||||||
if (userAgent) {
|
// if (userAgent) {
|
||||||
await page.setUserAgent(userAgent);
|
// await page.setUserAgent(userAgent);
|
||||||
}
|
// }
|
||||||
await page.goto(url, { waitUntil: 'networkidle0' });
|
// await page.goto(url, { waitUntil: "networkidle0" });
|
||||||
const pageContent = await page.content();
|
// const pageContent = await page.content();
|
||||||
return pageContent;
|
// return pageContent;
|
||||||
});
|
// });
|
||||||
|
|
||||||
// 请求拦截
|
// 请求拦截
|
||||||
request.interceptors.request.use(
|
request.interceptors.request.use(
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
const getTime = (timeInput: string | number): number => {
|
interface CurrentDateTime {
|
||||||
|
year: number;
|
||||||
|
month: number;
|
||||||
|
day: number;
|
||||||
|
hour: number;
|
||||||
|
minute: number;
|
||||||
|
second: number;
|
||||||
|
}
|
||||||
|
export const getTime = (timeInput: string | number): number => {
|
||||||
try {
|
try {
|
||||||
let num: number | string;
|
let num: number | string;
|
||||||
// 尝试将输入转换为数字
|
// 尝试将输入转换为数字
|
||||||
@@ -25,4 +33,15 @@ const getTime = (timeInput: string | number): number => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default getTime;
|
export const getCurrentDateTime = (): CurrentDateTime => {
|
||||||
|
const now = dayjs();
|
||||||
|
|
||||||
|
return {
|
||||||
|
year: now.year(),
|
||||||
|
month: now.month() + 1,
|
||||||
|
day: now.date(),
|
||||||
|
hour: now.hour(),
|
||||||
|
minute: now.minute(),
|
||||||
|
second: now.second(),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user