UNPKG

rsshub

Version:
71 lines (70 loc) 2.39 kB
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs"; import { t as md5 } from "./md5-CpIHIxCO.mjs"; import { randomBytes } from "node:crypto"; import { load } from "cheerio"; import CryptoJS from "crypto-js"; //#region lib/routes/mafengwo/utils.ts const key = CryptoJS.enc.Utf8.parse("tg09It3*9h"); /** * `w_tsfp`=`base64(RC4(key, payload))` */ const generateWTsfp = (url) => { const now = Date.now(); const fingerprint = randomBytes(16).toString("hex"); const salt = randomBytes(16).toString("hex"); const payload = JSON.stringify({ timestamp: now, basets: now, loadts: now, fingerprint, abnormal: "0".repeat(32), referer: encodeURIComponent("https://www.mafengwo.cn/"), uri: encodeURIComponent(url), checksum: md5(url + fingerprint + salt + now) }); return `x-waf-captcha-referer=; w_tsfp=${CryptoJS.RC4.encrypt(CryptoJS.enc.Utf8.parse(payload), key).ciphertext.toString(CryptoJS.enc.Base64)}`; }; const wafFetch = (url) => rofetch(url, { headers: { cookie: generateWTsfp(url) } }); //#endregion //#region lib/routes/mafengwo/ziyouxing.ts const route = { path: "/ziyouxing/:code", categories: ["travel"], example: "/mafengwo/ziyouxing/10186", parameters: { code: "目的地代码,可在该目的地页面的 URL 中找到" }, description: "目的地代码请参见 [这里](http://www.mafengwo.cn/mdd/)", features: { requireConfig: false, requirePuppeteer: false, antiCrawler: true, supportBT: false, supportPodcast: false, supportScihub: false }, name: "自由行", maintainers: ["nczitzk"], handler }; const baseUrl = "https://www.mafengwo.cn"; async function handler(ctx) { const { code } = ctx.req.param(); const rootUrl = `${baseUrl}/gonglve/ziyouxing/list/list_page?mddid=${code}&page=1`; const $ = load((await wafFetch(rootUrl)).html); const items = $("div.item").toArray().map((item) => { const $item = $(item); const summary = $item.find("ul li").toArray().map((li) => `<li>${$(li).text()}</li>`).join(""); return { title: $item.find("h3").text(), link: new URL($item.find("a").attr("href"), baseUrl).href, description: `<img src="${$item.find("img").attr("src")}"><ul>${summary}</ul>`, category: [$item.find("span.location").text()] }; }); return { title: load(await wafFetch(`${baseUrl}/gonglve/ziyouxing/mdd_${code}/`))("title").text(), link: rootUrl, item: items }; } //#endregion export { route };