feat: 新增 吾爱破解

This commit is contained in:
imsyy
2024-06-05 18:16:43 +08:00
parent 093312ea8c
commit a3bb42d26c
49 changed files with 2554 additions and 1209 deletions

View File

@@ -1 +1,2 @@
node_modules node_modules
dist/logs/

View File

@@ -59,6 +59,25 @@
| 中央气象台 | 全国气象预警 | weatheralarm | 🟢 | | 中央气象台 | 全国气象预警 | weatheralarm | 🟢 |
| 中国地震台 | 地震速报 | earthquake | 🟢 | | 中国地震台 | 地震速报 | earthquake | 🟢 |
## 使用
本项目支持 `Node.js` 调用,可在安装完成后调用 `serveHotApi` 来开启服务器
```bash
pnpm add dailyhot-api
```
```js
import serveHotApi from "dailyhot-api";
/**
* 启动服务器
* @param {Number} [port] - 端口号
* @returns {Promise<void>}
*/
serveHotApi(3000);
```
## ⚙️ 部署 ## ⚙️ 部署
具体使用说明可参考 [我的博客](https://blog.imsyy.top/posts/2024/0408),下方仅讲解基础操作: 具体使用说明可参考 [我的博客](https://blog.imsyy.top/posts/2024/0408),下方仅讲解基础操作:

View File

@@ -1,6 +1,6 @@
{ {
"name": "dailyhot-api", "name": "dailyhot-api",
"version": "2.0.0-rc.3", "version": "2.0.0-rc.4",
"description": "An Api on Today's Hot list", "description": "An Api on Today's Hot list",
"keywords": [ "keywords": [
"API", "API",
@@ -18,6 +18,16 @@
"author": "imsyy", "author": "imsyy",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/types.js", "types": "dist/types.js",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"files": [
"LICENSE",
"README.md",
"dist/**/*",
"src/types.d.ts",
"!dist/logs/**/*"
],
"scripts": { "scripts": {
"format": "prettier --write .", "format": "prettier --write .",
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts,.vue --fix", "lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts,.vue --fix",
@@ -28,24 +38,27 @@
}, },
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"@hono/node-server": "^1.9.1", "@hono/node-server": "^1.11.2",
"axios": "^1.6.8", "axios": "^1.7.2",
"cheerio": "1.0.0-rc.12", "cheerio": "1.0.0-rc.12",
"dayjs": "^1.11.11",
"dotenv": "^16.4.5", "dotenv": "^16.4.5",
"feed": "^4.2.2", "feed": "^4.2.2",
"hono": "^4.2.2", "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",
"rss-parser": "^3.13.0",
"winston": "^3.13.0" "winston": "^3.13.0"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^20.12.5", "@types/node": "^20.14.1",
"@typescript-eslint/eslint-plugin": "^7.5.0", "@typescript-eslint/eslint-plugin": "^7.12.0",
"@typescript-eslint/parser": "^7.5.0", "@typescript-eslint/parser": "^7.12.0",
"eslint": "^8.57.0", "eslint": "^8.57.0",
"prettier": "^3.2.5", "prettier": "^3.3.0",
"tsx": "^3.14.0", "tsx": "^3.14.0",
"typescript": "^5.4.4" "typescript": "^5.4.5"
}, },
"engines": { "engines": {
"node": ">=20" "node": ">=20"

2889
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -3,6 +3,8 @@ import { cors } from "hono/cors";
import { config } from "./config.js"; import { config } from "./config.js";
import { serveStatic } from "@hono/node-server/serve-static"; import { serveStatic } from "@hono/node-server/serve-static";
import { compress } from "hono/compress"; import { compress } from "hono/compress";
import { prettyJSON } from "hono/pretty-json";
import { trimTrailingSlash } from "hono/trailing-slash";
import logger from "./utils/logger.js"; import logger from "./utils/logger.js";
import registry from "./registry.js"; import registry from "./registry.js";
import robotstxt from "./robots.txt.js"; import robotstxt from "./robots.txt.js";
@@ -15,6 +17,12 @@ const app = new Hono();
// 压缩响应 // 压缩响应
app.use(compress()); app.use(compress());
// prettyJSON
app.use(prettyJSON());
// 尾部斜杠重定向
app.use(trimTrailingSlash());
// CORS // CORS
app.use( app.use(
"*", "*",

View File

@@ -27,7 +27,7 @@ const getNumericEnvVariable = (key: string, defaultValue: number): number => {
const value = getEnvVariable(key) ?? String(defaultValue); const value = getEnvVariable(key) ?? String(defaultValue);
const parsedValue = parseInt(value, 10); const parsedValue = parseInt(value, 10);
if (isNaN(parsedValue)) { if (isNaN(parsedValue)) {
return defaultValue return defaultValue;
} }
return parsedValue; return parsedValue;
}; };

View File

@@ -4,12 +4,20 @@ import logger from "./utils/logger.js";
import app from "./app.js"; import app from "./app.js";
// 启动服务器 // 启动服务器
const serveHotApi = serve({ const serveHotApi = (port: number = config.PORT) => {
try {
const apiServer = serve({
fetch: app.fetch, fetch: app.fetch,
port: config.PORT, port,
}); });
logger.info(`🔥 DailyHot API 成功在端口 ${config.PORT} 上运行`); logger.info(`🔥 DailyHot API 成功在端口 ${config.PORT} 上运行`);
logger.info(`🔗 Local: 👉 http://localhost:${config.PORT}`); logger.info(`🔗 Local: 👉 http://localhost:${config.PORT}`);
return apiServer;
} catch (error) {
logger.error(error);
}
};
serveHotApi();
export default serveHotApi; export default serveHotApi;

View File

@@ -1,6 +1,7 @@
export type RouterType = { export type RouterType = {
"36kr": { "36kr": {
itemId: number; itemId: number;
publishTime: number;
templateMaterial: { templateMaterial: {
widgetTitle: string; widgetTitle: string;
authorName: string; authorName: string;
@@ -16,6 +17,7 @@ export type RouterType = {
hotEvent: { hotEvent: {
hotScore: number; hotScore: number;
}; };
timestamp: number;
miniProShareImage: string; miniProShareImage: string;
}; };
"netease-news": { "netease-news": {
@@ -23,6 +25,7 @@ export type RouterType = {
imgsrc: string; imgsrc: string;
source: string; source: string;
docid: string; docid: string;
ptime: string;
}; };
"zhihu-daily": { "zhihu-daily": {
id: number; id: number;
@@ -38,11 +41,21 @@ export type RouterType = {
cover: string; cover: string;
abstract: string; abstract: string;
source_id: number; source_id: number;
pubdate: string;
};
"52pojie": {
title: string;
link: string;
guid: string;
content?: string;
pubDate?: string;
author?: string;
}; };
bilibili: { bilibili: {
bvid: string; bvid: string;
title: string; title: string;
desc?: string; desc?: string;
pubdate: string;
pic?: string; pic?: string;
author?: string; author?: string;
video_review?: number; video_review?: number;
@@ -74,12 +87,14 @@ export type RouterType = {
note: string; note: string;
category: string; category: string;
raw_hot: number; raw_hot: number;
onboard_time: number;
}; };
zhihu: { zhihu: {
target: { target: {
id: number; id: number;
title: string; title: string;
excerpt: string; excerpt: string;
created: number;
}; };
children: [ children: [
{ {
@@ -92,6 +107,7 @@ export type RouterType = {
sentence_id: string; sentence_id: string;
word: string; word: string;
hot_value: number; hot_value: number;
event_time: number;
}; };
baidu: { baidu: {
index: number; index: number;
@@ -109,6 +125,7 @@ export type RouterType = {
subject: string; subject: string;
content: string; content: string;
cover: string; cover: string;
created_at: number;
}; };
stat: { stat: {
view_num: number; view_num: number;
@@ -130,6 +147,7 @@ export type RouterType = {
intro: string; intro: string;
cover: string; cover: string;
author: string; author: string;
publishTime: string;
}; };
}; };
toutiao: { toutiao: {
@@ -145,6 +163,7 @@ export type RouterType = {
name: string; name: string;
pic: string; pic: string;
praiseTimes: string; praiseTimes: string;
pubTimeLong: number;
}; };
sspai: { sspai: {
id: number; id: number;
@@ -152,6 +171,7 @@ export type RouterType = {
summary: string; summary: string;
banner: string; banner: string;
like_count: number; like_count: number;
released_time: number;
author: { author: {
nickname: string; nickname: string;
}; };
@@ -162,6 +182,7 @@ export type RouterType = {
sTitle: string; sTitle: string;
iTotalPlay: string; iTotalPlay: string;
iDocID: string; iDocID: string;
sCreated: string;
}; };
ngabbs: { ngabbs: {
tid: number; tid: number;
@@ -169,6 +190,7 @@ export type RouterType = {
author: string; author: string;
tpcurl: string; tpcurl: string;
replies: number; replies: number;
postdate: number;
}; };
tieba: { tieba: {
topic_id: number; topic_id: number;
@@ -177,6 +199,7 @@ export type RouterType = {
topic_pic: string; topic_pic: string;
topic_url: string; topic_url: string;
discuss_num: number; discuss_num: number;
create_time: number;
}; };
acfun: { acfun: {
dougaId: string; dougaId: string;
@@ -185,6 +208,7 @@ export type RouterType = {
contentDesc: string; contentDesc: string;
likeCount: number; likeCount: number;
coverUrl: string; coverUrl: string;
contributeTime: number;
}; };
hellogithub: { hellogithub: {
item_id: string; item_id: string;
@@ -193,6 +217,7 @@ export type RouterType = {
description: string; description: string;
summary: string; summary: string;
clicks_total: number; clicks_total: number;
updated_at: string;
}; };
v2ex: { v2ex: {
title: string; title: string;
@@ -223,6 +248,7 @@ export type RouterType = {
user_info: { user_info: {
username: string; username: string;
}; };
publish_time: string;
}; };
ifanr: { ifanr: {
buzz_original_url: string; buzz_original_url: string;
@@ -232,5 +258,6 @@ export type RouterType = {
post_title: string; post_title: string;
like_count: number; like_count: number;
comment_count: number; comment_count: number;
created_at: number;
}; };
}; };

View File

@@ -1,6 +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";
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";
@@ -65,6 +66,7 @@ const getList = async (options: Options, noCache: boolean) => {
title: item.widgetTitle, title: item.widgetTitle,
cover: item.widgetImage, cover: item.widgetImage,
author: item.authorName, author: item.authorName,
timestamp: getTime(v.publishTime),
hot: item.statCollect, hot: item.statCollect,
url: `https://www.36kr.com/p/${v.itemId}`, url: `https://www.36kr.com/p/${v.itemId}`,
mobileUrl: `https://m.36kr.com/p/${v.itemId}`, mobileUrl: `https://m.36kr.com/p/${v.itemId}`,

View File

@@ -2,6 +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";
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);
@@ -47,6 +48,7 @@ const getList = async (noCache: boolean) => {
title: v.title, title: v.title,
cover: v.cover, cover: v.cover,
desc: v.abstract, desc: v.abstract,
timestamp: getTime(v.pubdate),
url: v.url, url: v.url,
mobileUrl: v.url, mobileUrl: v.url,
})), })),

66
src/routes/52pojie.ts Normal file
View File

@@ -0,0 +1,66 @@
import type { RouterData, ListContext, Options } from "../types.js";
import type { RouterType } from "../router.types.js";
import { web } from "../utils/getData.js";
import { extractRss, parseRSS } from "../utils/parseRSS.js";
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 routeData: RouterData = {
name: "52pojie",
title: "吾爱破解",
type: "榜单",
parameData: {
type: {
name: "榜单分类",
type: {
tech: "新鲜出炉",
newthread: "技术分享",
hot: "人气热门",
digest: "精华采撷",
},
},
},
link: "https://www.52pojie.cn/",
total: data?.length || 0,
updateTime,
fromCache,
data,
};
return routeData;
};
const getList = async (options: Options, noCache: boolean) => {
const { type } = options;
const url = `https://www.52pojie.cn/forum.php?mod=guide&view=${type}&rss=1`;
const result = await web({
url,
noCache,
userAgent:
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Mobile Safari/537.36",
});
const parseData = async () => {
if (typeof result?.data === "string") {
const rssContent = extractRss(result.data);
return await parseRSS(rssContent);
} else {
return [];
}
};
const list = await parseData();
return {
fromCache: result.fromCache,
updateTime: result.updateTime,
data: list.map((v: RouterType["52pojie"]) => ({
id: v.guid,
title: v.title,
desc: v.content,
author: v.author,
timestamp: getTime(v.pubDate),
hot: null,
url: v.link,
mobileUrl: v.link,
})),
};
};

View File

@@ -1,6 +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";
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";
@@ -67,6 +68,7 @@ const getList = async (options: Options, noCache: boolean) => {
desc: v.contentDesc, desc: v.contentDesc,
cover: v.coverUrl, cover: v.coverUrl,
author: v.userName, author: v.userName,
timestamp: getTime(v.contributeTime),
hot: v.likeCount, hot: v.likeCount,
url: `https://www.acfun.cn/v/ac${v.dougaId}`, url: `https://www.acfun.cn/v/ac${v.dougaId}`,
mobileUrl: `https://m.acfun.cn/v/?ac=${v.dougaId}`, mobileUrl: `https://m.acfun.cn/v/?ac=${v.dougaId}`,

View File

@@ -55,6 +55,7 @@ const getList = async (options: Options, noCache: boolean) => {
desc: v.desc, desc: v.desc,
cover: v.img, cover: v.img,
author: v.show?.length ? v.show : "", author: v.show?.length ? v.show : "",
timestamp: null,
hot: Number(v.hotScore), hot: Number(v.hotScore),
url: `https://www.baidu.com/s?wd=${encodeURIComponent(v.query)}`, url: `https://www.baidu.com/s?wd=${encodeURIComponent(v.query)}`,
mobileUrl: v.rawUrl, mobileUrl: v.rawUrl,

View File

@@ -2,6 +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";
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";
@@ -65,6 +66,7 @@ const getList = async (options: Options, noCache: boolean) => {
desc: v.desc || "该视频暂无简介", desc: v.desc || "该视频暂无简介",
cover: v.pic.replace(/http:/, "https:"), cover: v.pic.replace(/http:/, "https:"),
author: v.owner.name, author: v.owner.name,
timestamp: getTime(v.pubdate),
hot: v.stat.view, hot: v.stat.view,
url: v.short_link_v2 || `https://www.bilibili.com/video/${v.bvid}`, url: v.short_link_v2 || `https://www.bilibili.com/video/${v.bvid}`,
mobileUrl: `https://m.bilibili.com/video/${v.bvid}`, mobileUrl: `https://m.bilibili.com/video/${v.bvid}`,
@@ -93,6 +95,7 @@ const getList = async (options: Options, noCache: boolean) => {
desc: v.desc || "该视频暂无简介", desc: v.desc || "该视频暂无简介",
cover: v.pic.replace(/http:/, "https:"), cover: v.pic.replace(/http:/, "https:"),
author: v.author, author: v.author,
timestamp: null,
hot: v.video_review, hot: v.video_review,
url: `https://www.bilibili.com/video/${v.bvid}`, url: `https://www.bilibili.com/video/${v.bvid}`,
mobileUrl: `https://m.bilibili.com/video/${v.bvid}`, mobileUrl: `https://m.bilibili.com/video/${v.bvid}`,

View File

@@ -42,6 +42,8 @@ const getList = async (noCache: boolean) => {
title: dom.find("h3 a").text().trim(), title: dom.find("h3 a").text().trim(),
cover: dom.find(".pic-wrap img").attr("src"), cover: dom.find(".pic-wrap img").attr("src"),
desc: dom.find(".block p").text().trim(), desc: dom.find(".block p").text().trim(),
timestamp: dom.find("span.pubtime").text().trim(),
hot: null,
url, url,
mobileUrl: `https://m.douban.com/group/topic/${getNumbers(url)}/`, mobileUrl: `https://m.douban.com/group/topic/${getNumbers(url)}/`,
}; };

View File

@@ -50,6 +50,7 @@ const getList = async (noCache: boolean) => {
title: `${score}${dom.find("a").attr("title")}`, title: `${score}${dom.find("a").attr("title")}`,
cover: dom.find("img").attr("src"), cover: dom.find("img").attr("src"),
desc: dom.find("p.pl").text(), desc: dom.find("p.pl").text(),
timestamp: null,
hot: getNumbers(dom.find("span.pl").text()), hot: getNumbers(dom.find("span.pl").text()),
url, url,
mobileUrl: `https://m.douban.com/movie/subject/${getNumbers(url)}/`, mobileUrl: `https://m.douban.com/movie/subject/${getNumbers(url)}/`,

View File

@@ -1,6 +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";
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);
@@ -51,6 +52,7 @@ const getList = async (noCache: boolean) => {
data: list.map((v: RouterType["douyin"]) => ({ data: list.map((v: RouterType["douyin"]) => ({
id: v.sentence_id, id: v.sentence_id,
title: v.word, title: v.word,
timestamp: getTime(v.event_time),
hot: v.hot_value, hot: v.hot_value,
url: `https://www.douyin.com/hot/${encodeURIComponent(v.sentence_id)}`, url: `https://www.douyin.com/hot/${encodeURIComponent(v.sentence_id)}`,
mobileUrl: `https://www.douyin.com/hot/${encodeURIComponent(v.sentence_id)}`, mobileUrl: `https://www.douyin.com/hot/${encodeURIComponent(v.sentence_id)}`,

View File

@@ -1,6 +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";
const mappings = { const mappings = {
O_TIME: "发震时刻(UTC+8)", O_TIME: "发震时刻(UTC+8)",
@@ -68,6 +69,8 @@ const getList = async (options: Options, noCache: boolean) => {
id: NEW_DID, id: NEW_DID,
title: `${LOCATION_C}发生${M}级地震`, title: `${LOCATION_C}发生${M}级地震`,
desc: contentBuilder.join("\n"), desc: contentBuilder.join("\n"),
timestamp: getTime(v["O_TIME"]),
hot: null,
url: `https://news.ceic.ac.cn/${NEW_DID}.html`, url: `https://news.ceic.ac.cn/${NEW_DID}.html`,
mobileUrl: `https://news.ceic.ac.cn/${NEW_DID}.html`, mobileUrl: `https://news.ceic.ac.cn/${NEW_DID}.html`,
}; };

View File

@@ -1,6 +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";
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";
@@ -44,6 +45,7 @@ const getList = async (options: Options, noCache: boolean) => {
desc: data.content, desc: data.content,
cover: data.cover, cover: data.cover,
author: v.user.nickname, author: v.user.nickname,
timestamp: getTime(data.created_at),
hot: v.stat.view_num, hot: v.stat.view_num,
url: `https://www.miyoushe.com/ys/article/${data.post_id}`, url: `https://www.miyoushe.com/ys/article/${data.post_id}`,
mobileUrl: `https://m.miyoushe.com/ys/#/article/${data.post_id}`, mobileUrl: `https://m.miyoushe.com/ys/#/article/${data.post_id}`,

View File

@@ -1,6 +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";
export const handleRoute = async (c: ListContext, noCache: boolean) => { export const handleRoute = async (c: ListContext, noCache: boolean) => {
const sort = c.req.query("sort") || "hot"; const sort = c.req.query("sort") || "hot";
@@ -41,6 +42,7 @@ const getList = async (options: Options, noCache: boolean) => {
title: v.title, title: v.title,
desc: v.summary, desc: v.summary,
author: v.author, author: v.author,
timestamp: getTime(v.updated_at),
hot: v.clicks_total, hot: v.clicks_total,
url: `https://hellogithub.com/repository/${v.item_id}`, url: `https://hellogithub.com/repository/${v.item_id}`,
mobileUrl: `https://hellogithub.com/repository/${v.item_id}`, mobileUrl: `https://hellogithub.com/repository/${v.item_id}`,

View File

@@ -1,6 +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";
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";
@@ -44,6 +45,7 @@ const getList = async (options: Options, noCache: boolean) => {
desc: data.content, desc: data.content,
cover: data.cover || v.image_list[0].url, cover: data.cover || v.image_list[0].url,
author: v.user.nickname, author: v.user.nickname,
timestamp: getTime(data.created_at),
hot: v.stat.view_num, hot: v.stat.view_num,
url: `https://www.miyoushe.com/bh3/article/${data.post_id}`, url: `https://www.miyoushe.com/bh3/article/${data.post_id}`,
mobileUrl: `https://m.miyoushe.com/bh3/#/article/${data.post_id}`, mobileUrl: `https://m.miyoushe.com/bh3/#/article/${data.post_id}`,

View File

@@ -1,6 +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";
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);
@@ -44,6 +45,8 @@ const getList = async (noCache: boolean) => {
title: titleProcessing(v.content).title, title: titleProcessing(v.content).title,
desc: titleProcessing(v.content).intro, desc: titleProcessing(v.content).intro,
author: v.user_info.username, author: v.user_info.username,
timestamp: getTime(v.publish_time),
hot: null,
url: v.url || "https://www.huxiu.com/moment/", url: v.url || "https://www.huxiu.com/moment/",
mobileUrl: v.url || "https://m.huxiu.com/moment/", mobileUrl: v.url || "https://m.huxiu.com/moment/",
})), })),

View File

@@ -1,6 +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";
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);
@@ -29,6 +30,7 @@ const getList = async (noCache: boolean) => {
id: v.id, id: v.id,
title: v.post_title, title: v.post_title,
desc: v.post_content, desc: v.post_content,
timestamp: getTime(v.created_at),
hot: v.like_count || v.comment_count, hot: v.like_count || v.comment_count,
url: `https://www.ifanr.com/${v.id}` || v.buzz_original_url, url: `https://www.ifanr.com/${v.id}` || v.buzz_original_url,
mobileUrl: `https://www.ifanr.com/digest/${v.id}` || v.buzz_original_url, mobileUrl: `https://www.ifanr.com/digest/${v.id}` || v.buzz_original_url,

View File

@@ -1,6 +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";
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);
@@ -35,11 +36,15 @@ const getList = async (noCache: boolean) => {
const listData = listDom.toArray().map((item) => { const listData = listDom.toArray().map((item) => {
const dom = $(item); const dom = $(item);
const href = dom.find("a").attr("href"); const href = dom.find("a").attr("href");
const time = dom.find("span.time").text().trim();
const match = time.match(/'([^']+)'/);
const dateTime = match ? match[1] : null;
return { return {
id: href ? Number(replaceLink(href, true)) : 100000, id: href ? Number(replaceLink(href, true)) : 100000,
title: dom.find(".newsbody h2").text().trim(), title: dom.find(".newsbody h2").text().trim(),
desc: dom.find(".newsbody p").text().trim(), desc: dom.find(".newsbody p").text().trim(),
cover: dom.find("img").attr("data-original"), cover: dom.find("img").attr("data-original"),
timestamp: getTime(dateTime),
hot: Number(dom.find(".comment").text().replace(/\D/g, "")), hot: Number(dom.find(".comment").text().replace(/\D/g, "")),
url: href || undefined, url: href || undefined,
mobileUrl: href ? replaceLink(href) : undefined, mobileUrl: href ? replaceLink(href) : undefined,

View File

@@ -43,6 +43,7 @@ const getList = async (noCache: boolean) => {
id: href ? Number(replaceLink(href, true)) : 100000, id: href ? Number(replaceLink(href, true)) : 100000,
title: dom.find(".plc-title").text().trim(), title: dom.find(".plc-title").text().trim(),
cover: dom.find("img").attr("data-original"), cover: dom.find("img").attr("data-original"),
timestamp: dom.find("span.post-time").text().trim(),
hot: Number(dom.find(".review-num").text().replace(/\D/g, "")), hot: Number(dom.find(".review-num").text().replace(/\D/g, "")),
url: href ? replaceLink(href) : undefined, url: href ? replaceLink(href) : undefined,
mobileUrl: href || undefined, mobileUrl: href || undefined,

View File

@@ -45,6 +45,8 @@ const getList = async (noCache: boolean) => {
cover: dom.find("img").attr("src"), cover: dom.find("img").attr("src"),
desc: dom.find("p.abstract").text()?.trim(), desc: dom.find("p.abstract").text()?.trim(),
author: dom.find("a.nickname").text()?.trim(), author: dom.find("a.nickname").text()?.trim(),
hot: null,
timestamp: null,
url: `https://www.jianshu.com${href}`, url: `https://www.jianshu.com${href}`,
mobileUrl: `https://www.jianshu.com${href}`, mobileUrl: `https://www.jianshu.com${href}`,
}; };

View File

@@ -29,6 +29,7 @@ const getList = async (noCache: boolean) => {
title: v.content.title, title: v.content.title,
author: v.author.name, author: v.author.name,
hot: v.content_counter.hot_rank, hot: v.content_counter.hot_rank,
timestamp: null,
url: `https://juejin.cn/post/${v.content.content_id}`, url: `https://juejin.cn/post/${v.content.content_id}`,
mobileUrl: `https://juejin.cn/post/${v.content.content_id}`, mobileUrl: `https://juejin.cn/post/${v.content.content_id}`,
})), })),

View File

@@ -1,6 +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";
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);
@@ -31,6 +32,7 @@ const getList = async (noCache: boolean) => {
cover: `https:${v.sIMG}`, cover: `https:${v.sIMG}`,
author: v.sAuthor, author: v.sAuthor,
hot: Number(v.iTotalPlay), hot: Number(v.iTotalPlay),
timestamp: getTime(v.sCreated),
url: `https://lol.qq.com/news/detail.shtml?docid=${encodeURIComponent(v.iDocID)}`, url: `https://lol.qq.com/news/detail.shtml?docid=${encodeURIComponent(v.iDocID)}`,
mobileUrl: `https://lol.qq.com/news/detail.shtml?docid=${encodeURIComponent(v.iDocID)}`, mobileUrl: `https://lol.qq.com/news/detail.shtml?docid=${encodeURIComponent(v.iDocID)}`,
})), })),

View File

@@ -1,6 +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";
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);
@@ -29,6 +30,8 @@ const getList = async (noCache: boolean) => {
title: v.title, title: v.title,
cover: v.imgsrc, cover: v.imgsrc,
author: v.source, author: v.source,
hot: null,
timestamp: getTime(v.ptime),
url: `https://www.163.com/dy/article/${v.docid}.html`, url: `https://www.163.com/dy/article/${v.docid}.html`,
mobileUrl: `https://m.163.com/dy/article/${v.docid}.html`, mobileUrl: `https://m.163.com/dy/article/${v.docid}.html`,
})), })),

View File

@@ -1,6 +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";
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);
@@ -48,6 +49,7 @@ const getList = async (noCache: boolean) => {
title: v.subject, title: v.subject,
author: v.author, author: v.author,
hot: v.replies, hot: v.replies,
timestamp: getTime(v.postdate),
url: `https://bbs.nga.cn${v.tpcurl}`, url: `https://bbs.nga.cn${v.tpcurl}`,
mobileUrl: `https://bbs.nga.cn${v.tpcurl}`, mobileUrl: `https://bbs.nga.cn${v.tpcurl}`,
})), })),

View File

@@ -1,6 +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";
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);
@@ -19,7 +20,8 @@ export const handleRoute = async (_: undefined, noCache: boolean) => {
const getList = async (noCache: boolean) => { const getList = async (noCache: boolean) => {
const url = `https://r.inews.qq.com/gw/event/hot_ranking_list?page_size=50`; const url = `https://r.inews.qq.com/gw/event/hot_ranking_list?page_size=50`;
const result = await get({ url, noCache });const list = result.data.idlist[0].newslist.slice(1); const result = await get({ url, noCache });
const list = result.data.idlist[0].newslist.slice(1);
return { return {
fromCache: result.fromCache, fromCache: result.fromCache,
updateTime: result.updateTime, updateTime: result.updateTime,
@@ -30,6 +32,7 @@ const getList = async (noCache: boolean) => {
cover: v.miniProShareImage, cover: v.miniProShareImage,
author: v.source, author: v.source,
hot: v.hotEvent.hotScore, hot: v.hotEvent.hotScore,
timestamp: getTime(v.timestamp),
url: `https://new.qq.com/rain/a/${v.id}`, url: `https://new.qq.com/rain/a/${v.id}`,
mobileUrl: `https://view.inews.qq.com/k/${v.id}`, mobileUrl: `https://view.inews.qq.com/k/${v.id}`,
})), })),

View File

@@ -1,6 +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";
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") || "热门文章";
@@ -38,6 +39,7 @@ const getList = async (options: Options, noCache: boolean) => {
desc: v.summary, desc: v.summary,
cover: v.banner, cover: v.banner,
author: v.author.nickname, author: v.author.nickname,
timestamp: getTime(v.released_time),
hot: v.like_count, hot: v.like_count,
url: `https://sspai.com/post/${v.id}`, url: `https://sspai.com/post/${v.id}`,
mobileUrl: `https://sspai.com/post/${v.id}`, mobileUrl: `https://sspai.com/post/${v.id}`,

View File

@@ -1,6 +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";
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";
@@ -44,6 +45,7 @@ const getList = async (options: Options, noCache: boolean) => {
desc: data.content, desc: data.content,
cover: data.cover, cover: data.cover,
author: v.user.nickname, author: v.user.nickname,
timestamp: getTime(data.created_at),
hot: v.stat.view_num, hot: v.stat.view_num,
url: `https://www.miyoushe.com/sr/article/${data.post_id}`, url: `https://www.miyoushe.com/sr/article/${data.post_id}`,
mobileUrl: `https://m.miyoushe.com/sr/#/article/${data.post_id}`, mobileUrl: `https://m.miyoushe.com/sr/#/article/${data.post_id}`,

View File

@@ -1,6 +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";
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);
@@ -29,6 +30,7 @@ const getList = async (noCache: boolean) => {
title: v.name, title: v.name,
cover: v.pic, cover: v.pic,
hot: Number(v.praiseTimes), hot: Number(v.praiseTimes),
timestamp: getTime(v.pubTimeLong),
url: `https://www.thepaper.cn/newsDetail_forward_${v.contId}`, url: `https://www.thepaper.cn/newsDetail_forward_${v.contId}`,
mobileUrl: `https://m.thepaper.cn/newsDetail_forward_${v.contId}`, mobileUrl: `https://m.thepaper.cn/newsDetail_forward_${v.contId}`,
})), })),

View File

@@ -1,6 +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";
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);
@@ -31,6 +32,7 @@ const getList = async (noCache: boolean) => {
desc: v.topic_desc, desc: v.topic_desc,
cover: v.topic_pic, cover: v.topic_pic,
hot: v.discuss_num, hot: v.discuss_num,
timestamp: getTime(v.create_time),
url: v.topic_url, url: v.topic_url,
mobileUrl: v.topic_url, mobileUrl: v.topic_url,
})), })),

View File

@@ -1,6 +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";
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);
@@ -28,6 +29,7 @@ const getList = async (noCache: boolean) => {
id: v.ClusterIdStr, id: v.ClusterIdStr,
title: v.Title, title: v.Title,
cover: v.Image.url, cover: v.Image.url,
timestamp: getTime(v.ClusterIdStr),
hot: Number(v.HotValue), hot: Number(v.HotValue),
url: `https://www.toutiao.com/trending/${v.ClusterIdStr}/`, url: `https://www.toutiao.com/trending/${v.ClusterIdStr}/`,
mobileUrl: `https://api.toutiaoapi.com/feoffline/amos_land/new/html/main/index.html?topic_id=${v.ClusterIdStr}`, mobileUrl: `https://api.toutiaoapi.com/feoffline/amos_land/new/html/main/index.html?topic_id=${v.ClusterIdStr}`,

View File

@@ -40,6 +40,7 @@ const getList = async (options: Options, noCache: boolean) => {
title: v.title, title: v.title,
desc: v.content, desc: v.content,
author: v.member.username, author: v.member.username,
timestamp: null,
hot: v.replies, hot: v.replies,
url: v.url, url: v.url,
mobileUrl: v.url, mobileUrl: v.url,

View File

@@ -1,6 +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";
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") || "";
@@ -29,6 +30,8 @@ const getList = async (options: Options, noCache: boolean) => {
const url = `http://www.nmc.cn/rest/findAlarm?pageNo=1&pageSize=20&signaltype=&signallevel=&province=${encodeURIComponent(province)}`; const url = `http://www.nmc.cn/rest/findAlarm?pageNo=1&pageSize=20&signaltype=&signallevel=&province=${encodeURIComponent(province)}`;
const result = await get({ url, noCache }); const result = await get({ url, noCache });
const list = result.data.data.page.list; const list = result.data.data.page.list;
console.log(list);
return { return {
fromCache: result.fromCache, fromCache: result.fromCache,
updateTime: result.updateTime, updateTime: result.updateTime,
@@ -38,6 +41,8 @@ const getList = async (options: Options, noCache: boolean) => {
title: v.title, title: v.title,
desc: v.issuetime + " " + v.title, desc: v.issuetime + " " + v.title,
cover: v.pic, cover: v.pic,
timestamp: getTime(v.issuetime),
hot: null,
url: `http://nmc.cn${v.url}`, url: `http://nmc.cn${v.url}`,
mobileUrl: `http://nmc.cn${v.url}`, mobileUrl: `http://nmc.cn${v.url}`,
})), })),

View File

@@ -1,6 +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";
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);
@@ -32,6 +33,7 @@ const getList = async (noCache: boolean) => {
title: v.word, title: v.word,
desc: v.note || key, desc: v.note || key,
author: v.category, author: v.category,
timestamp: getTime(v.onboard_time),
hot: v.raw_hot, hot: v.raw_hot,
url: `https://s.weibo.com/weibo?q=${encodeURIComponent(key)}&t=31&band_rank=1&Refer=top`, url: `https://s.weibo.com/weibo?q=${encodeURIComponent(key)}&t=31&band_rank=1&Refer=top`,
mobileUrl: `https://s.weibo.com/weibo?q=${encodeURIComponent( mobileUrl: `https://s.weibo.com/weibo?q=${encodeURIComponent(

View File

@@ -2,6 +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";
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);
@@ -40,6 +41,7 @@ const getList = async (noCache: boolean) => {
author: data.author, author: data.author,
desc: data.intro, desc: data.intro,
cover: data.cover.replace("s_", "t9_"), cover: data.cover.replace("s_", "t9_"),
timestamp: getTime(data.publishTime),
hot: v.readingCount, hot: v.readingCount,
url: `https://weread.qq.com/web/bookDetail/${getWereadID(data.bookId)}`, url: `https://weread.qq.com/web/bookDetail/${getWereadID(data.bookId)}`,
mobileUrl: `https://weread.qq.com/web/bookDetail/${getWereadID(data.bookId)}`, mobileUrl: `https://weread.qq.com/web/bookDetail/${getWereadID(data.bookId)}`,

View File

@@ -37,6 +37,8 @@ const getList = async (noCache: boolean) => {
title: v.title, title: v.title,
cover: v.images[0], cover: v.images[0],
author: v.hint, author: v.hint,
hot: null,
timestamp: null,
url: v.url, url: v.url,
mobileUrl: v.url, mobileUrl: v.url,
})), })),

View File

@@ -1,6 +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";
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);
@@ -31,6 +32,7 @@ const getList = async (noCache: boolean) => {
title: data.title, title: data.title,
desc: data.excerpt, desc: data.excerpt,
cover: v.children[0].thumbnail, cover: v.children[0].thumbnail,
timestamp: getTime(data.created),
hot: parseInt(v.detail_text.replace(/[^\d]/g, "")) * 10000, hot: parseInt(v.detail_text.replace(/[^\d]/g, "")) * 10000,
url: `https://www.zhihu.com/question/${data.id}`, url: `https://www.zhihu.com/question/${data.id}`,
mobileUrl: `https://www.zhihu.com/question/${data.id}`, mobileUrl: `https://www.zhihu.com/question/${data.id}`,

View File

@@ -10,7 +10,8 @@ export type ListItem = {
cover?: string; cover?: string;
author?: string; author?: string;
desc?: string; desc?: string;
hot?: number; hot: number | null;
timestamp: number | string | null;
url: string | undefined; url: string | undefined;
mobileUrl: string | undefined; mobileUrl: string | undefined;
}; };
@@ -50,7 +51,18 @@ export type Post = {
originaInfo?: boolean; originaInfo?: boolean;
}; };
export type Web = {
url: string;
timeout?: number;
noCache?: boolean;
ttl?: number;
userAgent?: string;
};
// 参数类型 // 参数类型
export type Options = { export type Options = {
[key: string]: string | undefined; [key: string]: string | undefined;
}; };
// serveHotApi
export default function serveHotApi(port?: number): unknown;

View File

@@ -1,6 +1,7 @@
import type { Get, Post } 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 puppeteer from "puppeteer";
import logger from "./logger.js"; import logger from "./logger.js";
import axios from "axios"; import axios from "axios";
@@ -98,3 +99,40 @@ export const post = async (options: Post) => {
throw error; throw error;
} }
}; };
// puppeteer
export const web = async (options: Web) => {
const { url, noCache, ttl = config.CACHE_TTL, userAgent } = options;
logger.info("使用 Puppeteer 发起页面请求", options);
try {
// 检查缓存
if (noCache) {
delCache(url);
} else {
const cachedData = getCache(url);
if (cachedData) {
logger.info("采用缓存", { url });
return { fromCache: true, data: cachedData.data, updateTime: cachedData.updateTime };
}
}
// 缓存不存在时使用 Puppeteer 请求页面
logger.info("启动浏览器请求页面", { url });
const browser = await puppeteer.launch();
const page = await browser.newPage();
// 其他 Puppeteer 操作
if (userAgent) page.setUserAgent(userAgent);
await page.goto(url, { waitUntil: "networkidle0" });
// 获取页面内容
const pageContent = await page.evaluate(() => document.body.innerHTML);
await browser.close();
// 存储新获取的数据到缓存
const updateTime = new Date().toISOString();
setCache(url, { data: pageContent, updateTime }, ttl);
// 返回数据
logger.info("页面内容获取成功");
return { fromCache: false, data: pageContent, updateTime };
} catch (error) {
logger.error("Puppeteer 请求出错", error);
throw error;
}
};

28
src/utils/getTime.ts Normal file
View File

@@ -0,0 +1,28 @@
import dayjs from "dayjs";
const getTime = (timeInput: string | number): number => {
try {
let num: number | string;
// 尝试将输入转换为数字
if (typeof timeInput === "string") {
num = Number(timeInput);
// 检查转换结果是否为有效数字
if (isNaN(num)) {
// 处理为字符串的日期时间
return dayjs(timeInput).valueOf();
}
} else {
num = timeInput;
}
// 是否为毫秒级时间戳
if (num > 946684800000) {
return num;
} else {
return num * 1000;
}
} catch (error) {
return null;
}
};
export default getTime;

41
src/utils/parseRSS.ts Normal file
View File

@@ -0,0 +1,41 @@
import RSSParser from "rss-parser";
import logger from "./logger.js";
export const extractRss = (content: string): string | null => {
// 匹配 <rss> 标签及内容
const rssRegex = /(<rss[\s\S]*?<\/rss>)/i;
const matches = content.match(rssRegex);
return matches ? matches[0] : null;
};
export const parseRSS = async (rssContent: string) => {
const parser = new RSSParser();
// 是否为网址
const isUrl = (url: string) => {
try {
new URL(url);
return true;
} catch (_) {
return false;
}
};
try {
const feed = isUrl(rssContent)
? await parser.parseURL(rssContent)
: await parser.parseString(rssContent);
const items = feed.items.map((item) => ({
title: item.title, // 文章标题
link: item.link, // 文章链接
pubDate: item.pubDate, // 发布日期
author: item.creator ?? item.author, // 作者
content: item.content, // 内容
contentSnippet: item.contentSnippet, // 内容摘要
guid: item.guid, // 全局唯一标识符
categories: item.categories, // 分类
}));
// 返回解析数据
return items;
} catch (error) {
logger.error("解析 RSS 内容时出错:", error);
return null;
}
};

View File

@@ -1,12 +1,7 @@
import type { FC } from "hono/jsx"; import type { FC } from "hono/jsx";
import { css, Style } from "hono/css"; import { css, Style } from "hono/css";
type LayoutProps = { const Layout: FC = (props) => {
title: string;
children: JSX.Element | JSX.Element[];
};
const Layout: FC<LayoutProps> = (props) => {
const globalClass = css` const globalClass = css`
:-hono-global { :-hono-global {
* { * {

View File

@@ -20,7 +20,13 @@ const NotFound: FC = () => {
</div> </div>
<div class="control"> <div class="control">
<button id="home-button"> <button id="home-button">
<svg className="btn-icon" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"> <svg
className="btn-icon"
xmlns="http://www.w3.org/2000/svg"
width="32"
height="32"
viewBox="0 0 24 24"
>
<path <path
fill="currentColor" fill="currentColor"
d="M10 19v-5h4v5c0 .55.45 1 1 1h3c.55 0 1-.45 1-1v-7h1.7c.46 0 .68-.57.33-.87L12.67 3.6c-.38-.34-.96-.34-1.34 0l-8.36 7.53c-.34.3-.13.87.33.87H5v7c0 .55.45 1 1 1h3c.55 0 1-.45 1-1" d="M10 19v-5h4v5c0 .55.45 1 1 1h3c.55 0 1-.45 1-1v-7h1.7c.46 0 .68-.57.33-.87L12.67 3.6c-.38-.34-.96-.34-1.34 0l-8.36 7.53c-.34.3-.13.87.33.87H5v7c0 .55.45 1 1 1h3c.55 0 1-.45 1-1"