UNPKG

rsshub

Version:
92 lines (90 loc) 3.21 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import { t as config } from "./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 config_not_found_default } from "./config-not-found-Dyp3RlZZ.mjs"; import path from "node:path"; //#region lib/routes/zodgame/forum.ts init_esm_shims(); 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 += art(path.join(__dirname, "templates/forum-c3ab5e98.art"), { content: 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 }; } //#endregion export { route };