rsshub
Version:
Make RSS Great Again!
70 lines (68 loc) • 2.32 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 timezone } from "./timezone-CA9Huotp.mjs";
import { load } from "cheerio";
//#region lib/routes/cfmmc/index.ts
const route = {
path: "/:id{.+}?",
name: "Unknown",
maintainers: [],
handler
};
async function handler(ctx) {
const { id = "main/noticeannouncement/cfmmcnotice" } = ctx.req.param();
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 10;
const rootUrl = "http://www.cfmmc.com";
const apiUrl = new URL("servlet/json", rootUrl).href;
const currentUrl = new URL(id.endsWith("/") ? id : `${id}/`, rootUrl).href;
const { data: currentResponse } = await got_default(currentUrl);
const $ = load(currentResponse);
const catalogId = $("#catalogId").prop("value");
const { data: response } = await got_default.post(apiUrl, {
form: {
funcNo: 741e3,
catalog_id: catalogId,
branchNo: "",
curtPageNo: 1,
numPerPage: limit,
key_word: "",
start_date: "",
end_date: ""
},
headers: { referer: currentUrl }
});
let items = response.results?.[0].data.slice(0, limit).map((item) => ({
title: item.title,
link: new URL(item.url, rootUrl).href,
pubDate: timezone(parseDate(item.publish_date), 8)
})) ?? [];
items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => {
const { data: detailResponse } = await got_default(item.link);
const content = load(detailResponse);
item.title = content("div.article_title h2").text();
item.description = content("div.cont_txt").html();
return item;
})));
const author = "中国期货市场监控中心";
const image = new URL($("a.logo img").prop("src"), rootUrl).href;
return {
item: items,
title: `${author} - ${$("h3.SubPage_t3").text()}`,
link: currentUrl,
description: $("meta[name=\"Description\"]").prop("content"),
language: "zh",
image,
subtitle: $("meta[name=\"Keywords\"]").prop("content"),
author,
allowEmpty: true
};
}
//#endregion
export { route };