From 91775a076329ee7cca32a5dd1019a8ae4cd2a5f7 Mon Sep 17 00:00:00 2001 From: JianBing77 <13579ziw@gmail.com> Date: Fri, 19 Jul 2024 11:41:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9ENodeSeek=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 ++- src/routes/nodeseek.ts | 51 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/routes/nodeseek.ts diff --git a/package.json b/package.json index d399b06..f260fe9 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/routes/nodeseek.ts b/src/routes/nodeseek.ts new file mode 100644 index 0000000..06218e8 --- /dev/null +++ b/src/routes/nodeseek.ts @@ -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], + })), + }; +};