UNPKG

rsshub

Version:
183 lines (180 loc) 5.56 kB
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"; import { CookieJar } from "tough-cookie"; import pMap from "p-map"; //#region lib/routes/gdut/oa-news.ts const site = "https://oas.gdut.edu.cn/seeyon"; const typeMap = { department: { id: "-288156881891407086", name: "部处简讯" }, academy: { id: "-6133000885854714423", name: "学院简讯" }, notice: { id: "2945931106835317958", name: "校内通知" }, announcement: { id: "906433874899913754", name: "公示公告" }, tender_result: { id: "-1226046021292568614", name: "招标结果" }, tender_invite: { id: "-3656117696093796045", name: "招标公告" } }; function getArg(type) { return JSON.stringify([{ page: 1, size: 50 }, { subject: "", departmentName: "", newsType: type ? type.id : "", startDate: "", endDate: "", canLogin: "true" }]); } const route = { path: "/oa_news/:type?", categories: ["university"], example: "/gdut/oa_news/notice", parameters: { type: "通知类型,留空则获取所有分类" }, feature: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["oas.gdut.edu.cn/seeyon"], target: "/oa_news/" }], name: "通知公文网", maintainers: [ "jim-kirisame", "GamerNoTitle", "Richard-Zheng" ], handler, url: "oas.gdut.edu.cn/seeyon", description: `学校可能会因为 IP 来源非学校而做出一定的限制,建议在校内网络环境下使用 RSS 阅读器订阅。 | 类型 | 参数 | 可能需要校内访问 | | ---- | ---- | ---------------- | | 部处简讯 | department | 是 | | 学院简讯 | academy | 是 | | 校内通知 | notice | 是 | | 公示公告 | announcement | 是 | | 招标结果 | tender_result | 否 | | 招标公告 | tender_invite | 否 | ` }; async function handler(ctx) { const typeParam = ctx.req.param("type") ?? "notice"; if (typeMap[typeParam] === void 0) throw new Error("通知类型" + typeParam + "未定义"); const type = typeMap[typeParam]; const cookieJar = new CookieJar(); await got_default(site + "/ggIP.do?method=portalSeachMore&subject=&departmentName=&newsType=&startDate=&endDate=", { cookieJar }); const resp = await got_default.post(site + "/ajax.do?method=ajaxAction&managerName=ggManager&rnd=1", { cookieJar, form: { managerMethod: "kkFindListDatas", arguments: getArg(type) } }); if (!resp.data.data) throw new Error("文章列表获取失败,可能是被临时限制了访问,请稍后重试\n" + JSON.stringify(resp.data)); const results = await pMap(resp.data.data.map((item) => ({ title: item.title, guid: item.id, link: site + "/newsData.do?method=newsView&newsId=" + item.id, pubDate: timezone(parseDate(item.publishDate), 8), author: item.publishUserDepart, category: item.typeName })), async (data) => { const link = data.link; data.description = await cache_default.tryGet(link, async () => { const $ = load((await got_default(link, { cookieJar })).data); const node = $("#content"); node.find("*").filter(function() { return this.type === "comment" || this.tagName === "meta" || this.tagName === "style"; }).remove(); node.find("*").contents().filter(function() { return this.type === "comment" || this.tagName === "meta" || this.tagName === "style"; }).remove(); node.find("*").each(function() { if (this.attribs.style !== void 0) { const newSty = this.attribs.style.split(";").filter((s) => { const styBlocklist = [ "color:rgb(0,0,0)", "color:black", "background:rgb(255,255,255)", "background:white", "text-align:left", "text-align:justify", "font-style:normal", "font-weight:normal" ]; const styPrefixBlocklist = [ "font-family", "font-size", "background", "text-autospace", "text-transform", "letter-spacing", "line-height", "padding", "margin", "text-justify", "word-break", "vertical-align", "mso-", "-ms-" ]; const sty = s.trim(); if (styBlocklist.includes(sty.replaceAll(/\s+/g, ""))) return false; for (const prefix of styPrefixBlocklist) if (sty.startsWith(prefix)) return false; return true; }).join(";"); if (newSty) this.attribs.style = newSty; else delete this.attribs.style; } if (this.attribs.class && this.attribs.class.trim().startsWith("Mso")) delete this.attribs.class; if (this.attribs.lang) delete this.attribs.lang; if (this.tagName === "font" || this.tagName === "o:p") $(this).replaceWith(this.childNodes); if (this.tagName === "span" && !this.attribs.style) $(this).replaceWith(this.childNodes); }); node.find("span").each(function() { if (this.childNodes.length === 0) $(this).remove(); }); return node.html(); }); return data; }, { concurrency: 2 }); return { title: `广东工业大学通知公文网 - ` + type.name, link: site, description: `广东工业大学通知公文网`, item: results }; } //#endregion export { route };