UNPKG

rsshub

Version:
145 lines (140 loc) 4.18 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import { t as logger_default } from "./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 path from "node:path"; //#region lib/routes/mihoyo/bbs/official.ts init_esm_shims(); const GITS_MAP = { 1: "崩坏三", 2: "原神", 3: "崩坏二", 4: "未定事件簿", 6: "崩坏:星穹铁道", 8: "绝区零" }; const TYPE_MAP = { 1: "公告", 2: "活动", 3: "资讯" }; const GAME_SHORT_MAP = { 1: "bh3", 2: "ys", 3: "bh2", 4: "wd", 6: "sr", 8: "zzz" }; const OFFICIAL_PAGE_MAP = { 1: "6", 2: "28", 3: "31", 4: "33", 6: "53", 8: "58" }; var MiHoYoOfficialError = class extends Error { constructor(message) { super(message); this.name = "MiHoYoOfficialError"; } }; const getNewsList = async ({ gids, type, page_size, last_id }) => { return (await got_default({ method: "get", url: `https://bbs-api-static.miyoushe.com/painter/wapi/getNewsList?${new URLSearchParams({ client_type: "4", gids, type, page_size, last_id }).toString()}` }))?.data?.data?.list; }; const getPostContent = async (row, default_gid = "2") => { const post = row.post; const post_id = post.post_id; const url = `https://bbs-api.miyoushe.com/post/wapi/getPostFull?${new URLSearchParams({ post_id }).toString()}`; return await cache_default.tryGet(url, async () => { const res = await got_default(url); const fullRow = res?.data?.data?.post; if (!fullRow) throw new MiHoYoOfficialError(`mihoyo/bbs/official: getPostContent failed: ${url} - ${JSON.stringify(res)}`); const gid = fullRow?.post?.game_id || default_gid; const author = fullRow?.user?.nickname || ""; const content = fullRow?.post?.content || ""; const tags = fullRow?.topics?.map((item) => item.name) || []; const description = art(path.join(__dirname, "templates/official-b135d099.art"), { hasCover: post.has_cover, coverList: row.cover_list, content }); return { title: post.subject, link: `https://www.miyoushe.com/${GAME_SHORT_MAP[gid]}/article/${post_id}`, description, pubDate: parseDate(post.created_at * 1e3), category: tags, author }; }); }; const getPostContents = (list, default_gid = "2") => Promise.all(list.map((item) => getPostContent(item, default_gid).catch((error) => { if (error instanceof MiHoYoOfficialError) { logger_default.error(error.message); return null; } throw error; }))).then((items) => items.filter(Boolean)); const route = { path: "/bbs/official/:gids/:type?/:page_size?/:last_id?", categories: ["game"], example: "/mihoyo/bbs/official/2/3/20/", parameters: { gids: "游戏id", type: "公告类型,默认为 2(即 活动)", page_size: "分页大小,默认为 20 ", last_id: "跳过的公告数,例如指定为 40 就是从第 40 条公告开始,可用于分页" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "米游社 - 官方公告", maintainers: ["CaoMeiYouRen"], handler, description: `游戏 id | 崩坏三 | 原神 | 崩坏二 | 未定事件簿 | 星穹铁道 | 绝区零 | | ------ | ---- | ------ | ---------- | -------- | ------ | | 1 | 2 | 3 | 4 | 6 | 8 | 公告类型 | 公告 | 活动 | 资讯 | | ---- | ---- | ---- | | 1 | 2 | 3 |` }; async function handler(ctx) { const { gids, type = "2", page_size = "20", last_id = "" } = ctx.req.param(); const items = await getPostContents(await getNewsList({ gids, type, page_size, last_id }), gids); return { title: `米游社 - ${GITS_MAP[gids] || ""} - ${TYPE_MAP[type] || ""}`, link: `https://www.miyoushe.com/${GAME_SHORT_MAP[gids]}/home/${OFFICIAL_PAGE_MAP[gids]}?type=${type}`, item: items }; } //#endregion export { route };