UNPKG

rsshub

Version:
67 lines (66 loc) 2.01 kB
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs"; import { t as parseDate } from "./parse-date-CjhZE69i.mjs"; import { t as cache_default } from "./cache-CiDoUSLo.mjs"; import { t as timezone } from "./timezone-DE--ze1V.mjs"; //#region lib/routes/mihoyo/bh2.ts const route = { path: "/bh2/:type?", categories: ["game"], example: "/mihoyo/bh2/gach", parameters: { type: "公告种类,默认为 `all`" }, name: "崩坏 2 - 游戏公告", maintainers: ["deepred5"], description: `| 全部 | 最新公告 | 版本信息 | 祈愿信息 | 活动介绍 | | ---- | -------- | -------- | -------- | -------- | | all | new | version | gach | event |`, handler, url: "www.benghuai.com/index/" }; const typeArr = [ "new", "version", "gach", "event" ]; async function handler(ctx) { const { type = "all" } = ctx.req.param(); const baseUrl = "https://www.benghuai.com"; const response = await rofetch(`${baseUrl}/main/getIndexNotice`, { method: "POST", headers: { Referer: `${baseUrl}/index/`, "x-requested-with": "XMLHttpRequest" }, parseResponse: JSON.parse }); const data = (typeArr.includes(type) ? [type] : typeArr).flatMap((t) => response.data[t].map((item) => ({ ...item, index: typeArr.indexOf(t) + 1 }))); const list = new Map(data.map((item) => [item.id, item])).values().toArray().map((item) => ({ title: item.title, pubDate: timezone(parseDate(item.time), 8), link: `${baseUrl}/news/?para=${item.index}_${item.id}`, id: item.id })); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { item.description = (await rofetch(`${baseUrl}/news/getNoticeByID?id=${item.id}`, { method: "POST", headers: { Referer: item.link, "x-requested-with": "XMLHttpRequest" }, parseResponse: JSON.parse })).data.text; return item; }))); const title = `崩坏2-${type}`; return { title, link: `${baseUrl}/news/`, description: title, item: items }; } //#endregion export { route };