UNPKG

rsshub

Version:
60 lines (58 loc) 2.32 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 "./helpers-DxBp0Pty.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { load } from "cheerio"; //#region lib/routes/civitai/discussions.ts const route = { path: "/discussions/:modelId", categories: ["program-update"], example: "/civitai/discussions/4384", parameters: { modelId: "N" }, features: { requireConfig: [{ name: "CIVITAI_COOKIE", description: "" }], requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false, nsfw: true }, radar: [{ source: ["civitai.com/models/:modelId"] }], name: "Model discussions", maintainers: ["DIYgod"], handler, description: `::: warning Need to configure \`CIVITAI_COOKIE\` to obtain image information of NSFW models. :::` }; async function handler(ctx) { const params = ctx.req.param(); const modelId = Number.parseInt(params.modelId); const { data } = await got_default(`https://civitai.com/api/trpc/review.getAll,comment.getAll?batch=1&input=${encodeURIComponent(`{"0":{"json":{"modelId":${modelId},"limit":12,"sort":"newest","cursor":null},"meta":{"values":{"cursor":["undefined"]}}},"1":{"json":{"modelId":${modelId},"limit":12,"sort":"newest","cursor":null},"meta":{"values":{"cursor":["undefined"]}}}}`)}`, { headers: { Referer: `https://civitai.com/${modelId}`, cookie: config.civitai.cookie } }); const items = [...data[0].result.data.json.reviews, ...data[1].result.data.json.comments].map((item) => item.images?.length || item.content ? { title: item.content ? load(item.content).text() : "Image", link: `https://civitai.com/models/${params.modelId}`, description: `${(item.images || []).map((image) => `<image src="https://imagecache.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/${image.url}/width=${image.width}/${image.id}">`).join("\n")}${item.content}`, pubDate: parseDate(item.createdAt), author: item.user?.username, guid: item.id } : null).filter(Boolean); return { title: `Civitai model ${params.modelId} discussions`, link: `https://civitai.com/`, item: items }; } //#endregion export { route };