Skip to content

Commit

Permalink
feat: 新增NodeSeek接口
Browse files Browse the repository at this point in the history
  • Loading branch information
JianBing77 committed Jul 19, 2024
1 parent a742f9d commit 91775a0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"md5": "^2.3.0",
"node-cache": "^5.1.2",
"rss-parser": "^3.13.0",
"winston": "^3.13.0"
"winston": "^3.13.0",
"xml2js": "^0.4.23"
},
"devDependencies": {
"@types/node": "^20.14.2",
Expand Down
51 changes: 51 additions & 0 deletions src/routes/nodeseek.ts
Original file line number Diff line number Diff line change
@@ -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],
})),
};
};

0 comments on commit 91775a0

Please sign in to comment.