rsshub
Version:
Make RSS Great Again!
64 lines (61 loc) • 2.29 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import { load } from "cheerio";
//#region lib/routes/qianp/utils.ts
const getTokenAndSecret = (tryGet) => tryGet("qianp:token", async () => {
const response = await got_default("https://qianp.com/news/recommend/");
return {
token: response.headers["set-cookie"].find((cookie) => cookie.startsWith("token="))?.split(";")[0]?.split("=")[1],
secret: response.headers["set-cookie"].find((cookie) => cookie.startsWith("secret="))?.split(";")[0]?.split("=")[1]
};
});
//#endregion
//#region lib/routes/qianp/news.ts
const route = {
path: "/news/:path{.+}?",
name: "Unknown",
maintainers: [],
handler
};
async function handler(ctx) {
const baseUrl = "https://qianp.com";
const { path = "news/recommend" } = ctx.req.param();
const url = `${baseUrl}/${path}/`;
const { token, secret } = await getTokenAndSecret(cache_default.tryGet);
const headers = { cookie: token ? `t=${token}; r=${secret - 100}` : void 0 };
const { data: response } = await got_default(url, { headers });
const $ = load(response);
const list = $(".newslist .infor").toArray().map((item) => {
item = $(item);
const a = item.find("a").first();
return {
title: a.attr("title"),
link: a.attr("href")
};
});
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const { data: response$1 } = await got_default(item.link, { headers });
const $$1 = load(response$1);
item.category = [...new Set($$1("meta[name=keywords]").attr("content").split(","))];
item.author = $$1("meta[name=author]").attr("content");
item.pubDate = parseDate($$1("meta[property=\"bytedance:published_time\"]").attr("content"));
item.description = $$1(".news_center").html();
return item;
})));
return {
title: $("head title").text(),
description: $("meta[name=\"description\"]").attr("content"),
link: url,
image: `${baseUrl}/favicon.ico`,
item: items
};
}
//#endregion
export { route };