UNPKG

rsshub

Version:
97 lines (95 loc) 3.86 kB
import "./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 got_default } from "./got-KxxWdaxq.mjs"; import { t as config_not_found_default } from "./config-not-found-Dyp3RlZZ.mjs"; import { load } from "cheerio"; //#region lib/routes/sehuatang/user.ts const baseUrl = "https://sehuatang.org/"; const route = { path: "/user/:uid", categories: ["multimedia"], example: "/sehuatang/user/411096", parameters: { uid: "用户 uid, 可在用户主页 URL 中找到" }, features: { requireConfig: [{ name: "SEHUATANG_COOKIE", description: "" }], requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false, nsfw: true }, name: "作者文章", maintainers: ["JamYiz"], handler }; async function handler(ctx) { if (!config.sehuatang.cookie) throw new config_not_found_default("Sehuatang RSS is disabled due to the lack of <a href=\"https://docs.rsshub.app/deploy/config#route-specific-configurations\">relevant config</a>"); const link = `${baseUrl}home.php?mod=space&uid=${ctx.req.param("uid")}&do=thread&view=me&from=space`; const $ = load((await got_default(link, { headers: { Cookie: config.sehuatang.cookie, "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8" } })).data); const list = $("#delform tr:not(.th)").slice(0, ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 25).toArray().map((item) => { item = $(item); const a = item.find("th>a").first(); return { title: `[${item.find(".xg1").first().text()}] ${a.text()}`, link: baseUrl + a.attr("href"), author: $(".mt").first().text() }; }); const out = await Promise.all(list.map((info) => cache_default.tryGet(info.link, async () => { const $$1 = load((await got_default(info.link, { headers: { Cookie: config.sehuatang.cookie, "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8" } })).data); const postMessage = $$1("[id^='postmessage']").slice(0, 1); const images = $$1(postMessage).find("img"); for (const image of images) { const file = $$1(image).attr("file"); if (!file || file === "undefined") $$1(image).replaceWith(""); else $$1(image).replaceWith($$1(`<img src="${file}">`)); } const pattl = $$1(".pattl"); const pattlImages = $$1(pattl).find("img"); for (const pattlImage of pattlImages) { const file = $$1(pattlImage).attr("file"); if (!file || file === "undefined") $$1(pattlImage).replaceWith(""); else $$1(pattlImage).replaceWith($$1(`<img src="${file}" />`)); } postMessage.append($$1(pattl)); $$1("em[onclick]").remove(); info.description = (postMessage.html() || "抓取原帖失败").replaceAll("ignore_js_op", "div"); const dateString = $$1(".authi em").first().text(); const datetimeString = `${dateString.split(" ")[1]} ${dateString.split(" ")[2]}`; const timestamp = new Date(datetimeString).getTime(); info.pubDate = $$1(".authi em span").length > 0 ? parseDate($$1(".authi em span").attr("title")) : parseDate(timestamp); const magnet = postMessage.find("div.blockcode li").first().text(); const isMag = magnet.startsWith("magnet"); const torrent = postMessage.find("p.attnm a").attr("href"); if (isMag || torrent !== void 0) { info.enclosure_url = isMag ? magnet : new URL(torrent, baseUrl).href; info.enclosure_type = isMag ? "application/x-bittorrent" : "application/octet-stream"; } return info; }))); return { title: `${$(".mt").text()}的帖子-色花堂`, link, item: out }; } //#endregion export { route };