UNPKG

rsshub

Version:
108 lines (104 loc) 3.43 kB
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 "./proxy-Db7uGcYb.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { n as puppeteer_default } from "./puppeteer-DGmvuGvT.mjs"; import { load } from "cheerio"; //#region lib/routes/ccac/utils.ts const BASE_URL = "https://www.ccac.org.mo"; const LANG_TYPE = { en: "en-us", sc: "zh-cn", tc: "zh-hk", pt: "pt" }; const TYPE = { all: "全部", case: "案件發佈", Persuasion: "調查報告或勸喻", AnnualReport: "年度報告", PCANews: "公署消息" }; function langBase(lang) { return `${BASE_URL}/${lang}/news.html`; } function typeFilter(list, type) { return type === "全部" ? list : list.filter((item) => item.tags.some((tag) => tag.name === type)); } var utils_default = { TYPE, BASE_URL, LANG_TYPE, langBase, typeFilter }; //#endregion //#region lib/routes/ccac/news.ts const route = { path: "/news/:type/:lang?", categories: ["government"], example: "/ccac/news/all", parameters: { type: "Category", lang: "Language, default to `sc`. Supprot `en`(English), `sc`(Simplified Chinese), `tc`(Traditional Chinese) and `pt`(Portuguese)" }, features: { requireConfig: false, requirePuppeteer: true, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "Latest News", maintainers: ["linbuxiao"], handler, description: `Category | All | Detected Cases | Investigation Reports or Recommendations | Annual Reports | CCAC's Updates | | --- | -------------- | ---------------------------------------- | -------------- | -------------- | | all | case | Persuasion | AnnualReport | PCANews |` }; async function handler(ctx) { const browser = await puppeteer_default(); const lang = ctx.req.param("lang") ?? "sc"; const type = utils_default.TYPE[ctx.req.param("type")]; const BASE = utils_default.langBase(lang); const page = await browser.newPage(); await page.setRequestInterception(true); page.on("request", (request) => { request.resourceType() === "document" || request.resourceType() === "script" ? request.continue() : request.abort(); }); await page.goto(BASE, { waitUntil: "domcontentloaded" }); const articles = await page.evaluate(() => window.articles); await browser.close(); const list = utils_default.typeFilter(articles, type).slice(0, ctx.req.query("limit") ? Number(ctx.req.query("limit")) : 30).map((item) => ({ title: item.name, category: item.tags.map((tag) => tag.name), link: utils_default.BASE_URL + item.url, pubDate: parseDate(item.time, "YYYY-MM-DD") })); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const $ = load((await got_default({ method: "get", url: item.link })).data); $(".article_details_body > *").removeAttr("style"); item.description = $(".article_details_body").html(); return item; }))); return { title: `CCAC ${type}`, link: BASE, description: `CCAC ${type}`, language: ctx.req.param("lang") ? utils_default.LANG_TYPE[ctx.req.param("lang")] : utils_default.LANG_TYPE.sc, item: items }; } //#endregion export { route };