rsshub
Version:
Make RSS Great Again!
96 lines (94 loc) • 3.12 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./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 art } from "./render-BQo6B4tL.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import { t as timezone } from "./timezone-D8cuwzTY.mjs";
import path from "node:path";
import { load } from "cheerio";
//#region lib/routes/shmtu/portal.ts
init_esm_shims();
const bootstrapHost = "https://weixin.shmtu.edu.cn/dynamic/shmtuHttps";
const host = "https://portal.shmtu.edu.cn/api";
const loadDetail = async (link) => {
const response = await got_default.post(bootstrapHost, {
form: { interfaceUrl: link },
https: { rejectUnauthorized: false }
});
return JSON.parse(response.data);
};
const processFeed = (list, caches) => Promise.all(list.map((item) => caches.tryGet(item.link, async () => {
const detail = await loadDetail(item.link);
const files = detail.field_file;
const images = detail.field_image;
item.description = art(path.join(__dirname, "templates/portal-9c9e2508.art"), {
body: detail.body.und[0].safe_value,
images: images.length !== 0 && Object.keys(images).length !== 0 ? images.und : null,
files: files.length !== 0 && Object.keys(files).length !== 0 ? files.und : null
});
item.link = detail.path;
return item;
})));
const route = {
path: "/portal/:type",
categories: ["university"],
example: "/shmtu/portal/bmtzgg",
parameters: { type: "类型名称" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{ source: ["portal.shmtu.edu.cn/:type"] }],
name: "数字平台",
maintainers: ["imbytecat"],
handler,
description: `| 部门通知公告 | 学术与大型活动公告 | 部门动态 |
| ------------ | ------------------ | -------- |
| bmtzgg | xsydxhdgg | bmdt |`
};
async function handler(ctx) {
const type = ctx.req.param("type");
let info;
switch (type) {
case "bmtzgg":
info = "部门通知公告";
break;
case "xsydxhdgg":
info = "学术与大型活动公告";
break;
case "bmdt":
info = "部门动态";
break;
default:
info = "未知";
break;
}
const response = await got_default.post(bootstrapHost, {
form: { interfaceUrl: `${host}/${type}.json?page=0` },
https: { rejectUnauthorized: false }
});
const result = await processFeed(JSON.parse(response.data).map((item) => ({
title: load(item.title).text(),
link: `${host}/node/${item.nid}.json`,
pubDate: timezone(parseDate(item.created), 8),
category: item.field_department[0],
author: item.field_department[0]
})), cache_default);
return {
title: `上海海事大学 ${info}`,
link: "https://portal.shmtu.edu.cn/bumentongzhigonggao",
description: "上海海事大学 数字平台",
item: result
};
}
//#endregion
export { route };