UNPKG

rsshub

Version:
140 lines (137 loc) 4.24 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 cache_default } from "./cache-Bo__VnGm.mjs"; import "./helpers-DxBp0Pty.mjs"; import "./proxy-Db7uGcYb.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { t as invalid_parameter_default } from "./invalid-parameter-rr4AgGpp.mjs"; import { n as puppeteer_default } from "./puppeteer-DGmvuGvT.mjs"; import { load } from "cheerio"; //#region lib/routes/xsijishe/utils.ts const puppeteerGet = async (url, browser) => { const page = await browser.newPage(); const expectResourceTypes = new Set(["document", "script"]); await page.setRequestInterception(true); page.on("request", (request) => { expectResourceTypes.has(request.resourceType()) ? request.continue() : request.abort(); }); await page.goto(url, { waitUntil: "domcontentloaded" }); let html; html = await page.evaluate(() => document.documentElement.innerHTML); if (html.includes("抱歉,您尚未登录,没有权限访问该版块")) { await page.close(); return html; } await page.waitForSelector(".t_f"); html = await page.evaluate(() => document.documentElement.innerHTML); await page.close(); return html; }; //#endregion //#region lib/routes/xsijishe/rank.ts const baseUrl = "https://xsijishe.com"; const route = { path: "/rank/:type", categories: ["bbs"], example: "/xsijishe/rank/weekly", parameters: { type: { description: "排行榜类型", options: [{ value: "weekly", label: "周榜" }, { value: "monthly", label: "月榜" }] } }, features: { requireConfig: [{ name: "XSIJISHE_COOKIE", description: "" }, { name: "XSIJISHE_USER_AGENT", description: "" }], requirePuppeteer: true, antiCrawler: true, supportBT: false, supportPodcast: false, supportScihub: false, nsfw: true }, name: "排行榜", maintainers: ["akynazh", "AiraNadih"], handler }; async function handler(ctx) { const rankType = ctx.req.param("type"); let title; let index; if (rankType === "weekly") { title = "司机社综合周排行榜"; index = 0; } else if (rankType === "monthly") { title = "司机社综合月排行榜"; index = 1; } else throw new invalid_parameter_default("Invalid rank type"); const browser = await puppeteer_default(); let usePuppeteer = false; const url = `${baseUrl}/portal.php`; const headers = { "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8", Cookie: config.xsijishe.cookie, "User-Agent": config.xsijishe.userAgent }; const resp = await got_default(url, { headers }); const redirectMatch = resp.data.match(/window\.location\.href\s*=\s*"([^"]+)"/); if (redirectMatch) resp.data = (await got_default(`${baseUrl}${redirectMatch[1]}`, { headers })).data; const $ = load(resp.data); let items = $(".nex_recon_lists ul li").eq(index).find(".nex_recons_demens dl dd").toArray().map((item) => { item = $(item); const title$1 = item.find("h5").text().trim(); const link = item.find("a").attr("href"); const description = item.find("img").prop("outerHTML"); return { title: title$1, link: `${baseUrl}/${link}`, description }; }); if (items.length > 0) { const firstItem = items[0]; if (load((await got_default(firstItem.link, { headers })).data)(".t_f").first().length === 0) usePuppeteer = true; } items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { let data; if (usePuppeteer) data = await puppeteerGet(item.link, browser); else data = (await got_default(item.link, { headers })).data; const $$1 = load(data); const firstViewBox = $$1(".t_f").first(); if (firstViewBox.length === 1) { firstViewBox.find("img").each((_, img) => { img = $$1(img); if (img.attr("zoomfile")) { img.attr("src", img.attr("zoomfile")); img.removeAttr("zoomfile"); img.removeAttr("file"); } img.removeAttr("onmouseover"); }); item.description = firstViewBox.html(); } return item; }))); await browser.close(); return { title, link: url, description: title, item: items }; } //#endregion export { route };