UNPKG

rsshub

Version:
28 lines (26 loc) 1.73 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/taptap/utils.ts init_esm_shims(); const X_UA = (lang = "zh_CN") => `X-UA=${encodeURIComponent(`V=1&PN=WebApp&VN=0.1.0&LANG=${lang}&PLT=PC`)}`; const getRootUrl = (isIntl = false) => isIntl ? "https://www.taptap.io" : "https://www.taptap.cn"; const appDetail = (appId, lang = "zh_CN", isIntl = false) => cache_default.tryGet(`taptap:appDetail:${appId}:${lang}:${isIntl}`, async () => { return (await ofetch_default(`${getRootUrl(isIntl)}/webapiv2/group/v1/detail?app_id=${appId}&${X_UA(lang)}`, { headers: { Referer: `${getRootUrl(isIntl)}/app/${appId}` } })).data; }); const imagePost = (images) => art(path.join(__dirname, "templates/imagePost-75c674ab.art"), { images }); const topicPost = async (appId, topicId, lang = "zh_CN") => { const $ = load((await ofetch_default(`${getRootUrl(false)}/webapiv2/topic/v1/detail?id=${topicId}&${X_UA(lang)}`, { headers: { Referer: `${getRootUrl(false)}/app/${appId}` } })).data.first_post.contents.text, null, false); $("img").each((_, e) => { const $e = $(e); $e.attr("src", $e.attr("data-origin-url")); $e.removeAttr("data-origin-url"); }); return $.html(); }; const videoPost = (video) => art(path.join(__dirname, "templates/videoPost-d7476920.art"), { previewUrl: video.thumbnail.original_url || video.thumbnail.url }); //#endregion export { topicPost as a, imagePost as i, appDetail as n, videoPost as o, getRootUrl as r, X_UA as t };