UNPKG

rsshub

Version:
101 lines (99 loc) 3.25 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import path from "node:path"; import bbobHTML from "@bbob/html"; import presetHTML5 from "@bbob/preset-html5"; //#region lib/routes/1point3acres/utils.ts init_esm_shims(); const rootUrl = "https://instant.1point3acres.com"; const apiRootUrl = "https://api.1point3acres.com"; const types = { new: "最新帖子", hot: "热门帖子" }; const swapLinebreak = (tree) => tree.walk((node) => { if (typeof node === "string" && node === "\n") return { tag: "br", content: null }; return node; }); const ProcessThreads = async (tryGet, apiUrl, order) => { const response = await got_default({ method: "get", url: apiUrl, headers: { referer: rootUrl } }); return await Promise.all(response.data.threads.map((item) => { const result = { guid: item.tid, title: item.subject, author: item.author, link: `${rootUrl}/thread/${item.tid}`, description: item.summary, pubDate: parseDate((order === "" ? item.lastpost : item.dateline) * 1e3), category: [item.forum_name, ...item.tags ? item.tags.map((t) => t.displayname) : []] }; return tryGet(result.link, async () => { try { const thread = (await got_default({ method: "get", url: `${apiRootUrl}/api/v3/threads/${result.guid}`, headers: { referer: rootUrl } })).data.thread; const customPreset = presetHTML5.extend((tags) => ({ ...tags, attach: (node, { render }) => { const id = render(node.content); const attachment = thread.attachment_list.find((a) => a.aid === Number.parseInt(id)); if (attachment.isimage) return { tag: "img", attrs: { src: attachment.url } }; return { tag: "a", attrs: { href: `https://www.1point3acres.com/bbs/plugin.php?id=attachcenter:page&aid=${id}`, rel: "noopener", target: "_blank" }, content: `https://www.1point3acres.com/bbs/plugin.php?id=attachcenter:page&aid=${id}` }; }, url: (node) => { const link = Object.keys(node.attrs)[0]; if (link.startsWith("https://link.1p3a.com/?url=")) return { tag: "a", attrs: { href: decodeURIComponent(link.replace("https://link.1p3a.com/?url=", "")), rel: "noopener", target: "_blank" }, content: node.content }; return { tag: "a", attrs: { href: link, rel: "noopener", target: "_blank" }, content: node.content }; } })); result.description = bbobHTML(thread.message_bbcode, [customPreset(), swapLinebreak]); if (!thread.message_bbcode.includes("[attach]") && thread.attachment_list.length > 0) for (const a of thread.attachment_list) result.description += a.isimage === 1 ? "<br>" + art(path.join(__dirname, "templates/image-8260a861.art"), { url: a.url, height: a.height, width: a.width }) : ""; } catch {} return result; }); })); }; //#endregion export { types as i, apiRootUrl as n, rootUrl as r, ProcessThreads as t };