rsshub
Version:
Make RSS Great Again!
89 lines (87 loc) • 3.14 kB
JavaScript
import "./dist-Bog6z_OM.mjs";
import "./config-MQ-7ebJ_.mjs";
import "./logger-C4avouvV.mjs";
import "./ofetch-DKl_Ma9g.mjs";
import { t as parseDate } from "./parse-date-r5WDWHno.mjs";
import "./is-worker-DESPicPc.mjs";
import { t as cache_default } from "./cache-SV6W5EPy.mjs";
import "./helpers-Bo4JQYdN.mjs";
import { t as got_default } from "./got-CO-ndVl2.mjs";
import { t as invalid_parameter_default } from "./invalid-parameter-ByDtry1B.mjs";
import { t as renderDepthDescription } from "./depth-DRymCebk.mjs";
import { n as rootUrl, t as getSearchParams } from "./utils-BuzNXSy7.mjs";
import { load } from "cheerio";
//#region lib/routes/cls/depth.ts
const categories = {
1e3: "头条",
1003: "股市",
1135: "港股",
1007: "环球",
1005: "公司",
1118: "券商",
1110: "基金",
1006: "地产",
1032: "金融",
1119: "汽车",
1111: "科创",
1127: "创业版",
1160: "品见",
1124: "期货",
1176: "投教"
};
const route = {
path: "/depth/:category?",
categories: ["finance"],
example: "/cls/depth/1000",
parameters: { category: "分类代码,可在首页导航栏的目标网址 URL 中找到" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
name: "深度",
maintainers: ["nczitzk"],
handler,
description: `| 头条 | 股市 | 港股 | 环球 | 公司 | 券商 | 基金 | 地产 | 金融 | 汽车 | 科创 | 创业版 | 品见 | 期货 | 投教 |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ------ | ---- | ---- | ---- |
| 1000 | 1003 | 1135 | 1007 | 1005 | 1118 | 1110 | 1006 | 1032 | 1119 | 1111 | 1127 | 1160 | 1124 | 1176 |`
};
async function handler(ctx) {
const category = ctx.req.param("category") ?? "1000";
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 50;
const title = categories[category];
if (!title) throw new invalid_parameter_default("Bad category. See <a href=\"https://docs.rsshub.app/routes/finance#cai-lian-she-shen-du\">docs</a>");
const apiUrl = `${rootUrl}/v3/depth/home/assembled/${category}`;
const currentUrl = `${rootUrl}/depth?id=${category}`;
const response = await got_default({
method: "get",
url: apiUrl,
searchParams: getSearchParams()
});
let items = [...response.data.data.top_article, ...response.data.data.depth_list].slice(0, limit).map((item) => ({
title: item.title || item.brief,
link: `${rootUrl}/detail/${item.id}`,
pubDate: parseDate(item.ctime * 1e3),
author: item.source
}));
items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => {
const content = load((await got_default({
method: "get",
url: item.link
})).data);
const articleDetail = JSON.parse(content("script#__NEXT_DATA__").text()).props.initialState.detail.articleDetail;
item.author = articleDetail.author?.name ?? item.author ?? "";
item.description = renderDepthDescription(articleDetail);
return item;
})));
return {
title: `财联社 - ${title}`,
link: currentUrl,
item: items
};
}
//#endregion
export { route };