UNPKG

rsshub

Version:
96 lines (94 loc) 3.35 kB
import "./dist-Bog6z_OM.mjs"; import { t as config } from "./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 config_not_found_default } from "./config-not-found-zoFMPvbz.mjs"; import { Fragment, jsx, jsxs } from "hono/jsx/jsx-runtime"; import { renderToString } from "hono/jsx/dom/server"; //#region lib/routes/zodgame/forum.tsx const rootUrl = "https://zodgame.xyz"; const route = { path: "/forum/:fid?", categories: ["bbs"], example: "/zodgame/forum/13", parameters: { fid: "forum id, can be found in URL" }, features: { requireConfig: [{ name: "ZODGAME_COOKIE", description: "" }], requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false, nsfw: true }, name: "forum", maintainers: ["FeCCC"], handler }; async function handler(ctx) { const fid = ctx.req.param("fid"); const subUrl = `${rootUrl}/api/mobile/index.php?version=4&module=forumdisplay&fid=${fid}`; const cookie = config.zodgame.cookie; if (cookie === void 0) throw new config_not_found_default("Zodgame RSS is disabled due to the lack of <a href=\"https://docs.rsshub.app/deploy/config#route-specific-configurations\">relevant config</a>"); const info = (await got_default({ method: "get", url: subUrl, headers: { Cookie: cookie } })).data.Variables; const ThreadList = info.forum_threadlist.map((item) => { if (!info.threadtypes.types[item.typeid]) return; const type = info.threadtypes.types[item.typeid]; return { tid: item.tid, title: `[${type}] ${item.subject}`, author: item.author, link: `${rootUrl}/forum.php?mod=viewthread&tid=${item.tid}&extra=page%3D1`, category: type, pubDate: parseDate(item.dbdateline * 1e3) }; }).filter((item) => item !== void 0); const items = await Promise.all(ThreadList.map((item) => cache_default.tryGet(item.tid, async () => { const threadInfo = (await got_default({ method: "get", url: `${rootUrl}/api/mobile/index.php?version=4&module=viewthread&tid=${item.tid}`, headers: { Cookie: cookie } })).data.Variables; let description = ""; if (threadInfo.thread.freemessage) { description += threadInfo.thread.freemessage; description += renderDescription(threadInfo.postlist[0].message); } else description += threadInfo.postlist[0].message; return { title: item.title, author: item.author, link: item.link, description, category: item.category, pubDate: item.pubDate, guid: item.tid, upvotes: Number.parseInt(threadInfo.thread.recommend_add, 10), downvotes: Number.parseInt(threadInfo.thread.recommend_sub, 10), comments: Number.parseInt(threadInfo.thread.replies, 10) }; }))); return { title: `${info.forum.name} - ZodGame论坛`, link: `${rootUrl}/forum.php?mod=forumdisplay&fid=${fid}`, item: items }; } const renderDescription = (content) => renderToString(/* @__PURE__ */ jsxs(Fragment, { children: [ /* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsx("span", { children: content }) ] })); //#endregion export { route };