UNPKG

rsshub

Version:
107 lines (106 loc) 3.88 kB
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs"; import { t as got_default } from "./got-BTowW50G.mjs"; import { t as timezone } from "./timezone-BBvDwS_3.mjs"; import { jsx, jsxs } from "hono/jsx/jsx-runtime"; import crypto from "node:crypto"; import { renderToString } from "hono/jsx/dom/server"; //#region lib/routes/scmuseum/namespace.ts const namespace = { name: "Sichuan Museum", url: "www.scmuseum.cn", zh: { name: "四川博物院" } }; //#endregion //#region lib/routes/scmuseum/exhibition.tsx function getToken() { const key = "TYYY3OT3-TOCBW7OW-T33QMVJ3-2IUUVC22".replaceAll("-", ""); const t = (Math.random() + "").slice(-6) + Date.now(); const cipher = crypto.createCipheriv("aes-256-ecb", Buffer.from(key, "utf8"), null); cipher.setAutoPadding(true); let token = cipher.update(t, "utf8", "base64"); token += cipher.final("base64"); return token; } const route = { path: "/exhibition/:type?", categories: ["travel"], example: "/scmuseum/exhibition/temp", parameters: { type: "Exhibition type, supported values: base (常设展览) or temp (临时展览), default is all exhibitions." }, name: "Exhibition", maintainers: ["magazian"], radar: [{ source: ["www.scmuseum.cn/Visit/Exhibition"], target: "/exhibition" }], handler: async (ctx) => { const typeParam = ctx.req.param("type"); const apiConfig = { base: { endpoint: "queryExhibitionBaseList", name: "常设展览", isBase: true }, temp: { endpoint: "queryExhibitionTempList", name: "临时展览", isBase: false } }; const fetchTypes = typeParam ? [typeParam] : ["base", "temp"]; const museumName = namespace.zh?.name || namespace.name; const titleTag = fetchTypes.length === 2 ? "" : apiConfig[fetchTypes[0]].name; const items = (await Promise.all(fetchTypes.map(async (t) => { const config = apiConfig[t]; return ((await got_default({ method: "post", url: `https://www.scmuseum.cn/japi/sw-cms-cloud/api/${config.endpoint}`, headers: { Appid: "75d98ea426f4412eab623c9076365802", Token: getToken() }, json: { entity: { languageType: "CN" }, param: { pageNum: 1, pageSize: 6 } } })).data?.data?.records || []).map((item) => { const isBase = config.isBase; const title = isBase ? item.baseName : item.tempName; const linkId = isBase ? item.exhibitionBaseId : item.exhibitionTempId; const itemLink = isBase ? `https://www.scmuseum.cn/Visit/Exhibition/BaseExhibition/${linkId}` : `https://www.scmuseum.cn/Visit/Exhibition/ExhibitiomReview/${linkId}`; const pubDate = item.startTime ? timezone(parseDate(item.startTime), 8) : void 0; const startDate = item.startTime ? item.startTime.split(" ", 1)[0] : ""; const endDate = item.endTime ? item.endTime.split(" ", 1)[0] : ""; const location = isBase ? item.basePlace : item.tempPlace; return { title, link: itemLink, pubDate, description: renderToString(/* @__PURE__ */ jsxs("div", { children: [ /* @__PURE__ */ jsx("img", { src: `https://www.scmuseum.cn/file/${item.thumb}` }), /* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsxs("p", { children: [/* @__PURE__ */ jsx("b", { children: "地点:" }), location || "参考详情"] }), /* @__PURE__ */ jsxs("p", { children: [/* @__PURE__ */ jsx("b", { children: "开展:" }), startDate || "未定/常设"] }), /* @__PURE__ */ jsxs("p", { children: [/* @__PURE__ */ jsx("b", { children: "闭展:" }), endDate || "未定/常设"] }) ] })), _extra: { museumName, location, startDate, endDate } }; }); }))).flat(); return { title: `${museumName} - 展览${titleTag ? ` - ${titleTag}` : ""}`, link: "https://www.scmuseum.cn/Visit/Exhibition", language: "zh-CN", item: items }; } }; //#endregion export { route };