mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 13:14:55 +08:00
feat: 新增NodeSeek接口
This commit is contained in:
@@ -47,7 +47,8 @@
|
|||||||
"md5": "^2.3.0",
|
"md5": "^2.3.0",
|
||||||
"node-cache": "^5.1.2",
|
"node-cache": "^5.1.2",
|
||||||
"rss-parser": "^3.13.0",
|
"rss-parser": "^3.13.0",
|
||||||
"winston": "^3.13.0"
|
"winston": "^3.13.0",
|
||||||
|
"xml2js": "^0.4.23"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.14.2",
|
"@types/node": "^20.14.2",
|
||||||
|
|||||||
51
src/routes/nodeseek.ts
Normal file
51
src/routes/nodeseek.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import type { RouterData, ListContext, Options } from "../types.js";
|
||||||
|
import { get } from "../utils/getData.js";
|
||||||
|
import { parseStringPromise } from "xml2js";
|
||||||
|
|
||||||
|
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||||
|
const type = c.req.query("type") || "frontpage"; // NodeSeek 没有类型区分,可以忽略
|
||||||
|
const { fromCache, data, updateTime } = await getList({}, noCache);
|
||||||
|
const routeData: RouterData = {
|
||||||
|
name: "nodeseek",
|
||||||
|
title: "NodeSeek",
|
||||||
|
type: "最新",
|
||||||
|
params: {
|
||||||
|
type: {
|
||||||
|
name: "分类",
|
||||||
|
type: {
|
||||||
|
all: "所有",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
link: "https://www.nodeseek.com/",
|
||||||
|
total: data?.length || 0,
|
||||||
|
updateTime,
|
||||||
|
fromCache,
|
||||||
|
data,
|
||||||
|
};
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getList = async (options: Options, noCache: boolean) => {
|
||||||
|
const url = `https://rss.nodeseek.com/`;
|
||||||
|
const result = await get({ url, noCache });
|
||||||
|
|
||||||
|
const rssData = await parseStringPromise(result.data);
|
||||||
|
|
||||||
|
const list = rssData.rss.channel[0].item;
|
||||||
|
|
||||||
|
return {
|
||||||
|
fromCache: result.fromCache,
|
||||||
|
updateTime: result.updateTime,
|
||||||
|
data: list.map((v: any) => ({
|
||||||
|
id: v.guid[0]._,
|
||||||
|
title: v.title[0],
|
||||||
|
desc: v.description ? v.description[0] : "",
|
||||||
|
author: v["dc:creator"] ? v["dc:creator"][0] : "unknown",
|
||||||
|
timestamp: new Date(v.pubDate[0]).getTime(),
|
||||||
|
hot: null, // NodeSeek RSS 中没有类似于hot的字段
|
||||||
|
url: v.link[0],
|
||||||
|
mobileUrl: v.link[0],
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user