UNPKG

rsshub

Version:
67 lines (65 loc) 2.29 kB
import "./dist-Bog6z_OM.mjs"; import { t as config } from "./config-MQ-7ebJ_.mjs"; import "./logger-C4avouvV.mjs"; import { t as ofetch_default } from "./ofetch-DKl_Ma9g.mjs"; import "./is-worker-DESPicPc.mjs"; import { t as cache_default } from "./cache-SV6W5EPy.mjs"; import { t as config_not_found_default } from "./config-not-found-zoFMPvbz.mjs"; import { t as getHeaders } from "./utils-C_eMY8i8.mjs"; import { load } from "cheerio"; //#region lib/routes/smzdm/product.ts const route = { path: "/product/:id", categories: ["shopping"], example: "/smzdm/product/zm5vzpe", parameters: { id: "商品 id,网址上直接可以看到" }, features: { requireConfig: [{ name: "SMZDM_COOKIE", description: "什么值得买登录后的 Cookie 值" }], requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["wiki.smzdm.com/p/:id"], target: "/product/:id" }], name: "商品", maintainers: ["chesha1"], handler }; async function handler(ctx) { if (!config.smzdm.cookie) throw new config_not_found_default("什么值得买排行榜 is disabled due to the lack of SMZDM_COOKIE"); const link = `https://wiki.smzdm.com/p/${ctx.req.param("id")}`; const $ = load(await ofetch_default(link, { headers: getHeaders() })); const title = $("title").text(); const items = $("ul#feed-main-list li").toArray().map((elem) => { const altText = $(elem).find("img").attr("alt"); const link = $(elem).find("h5.feed-block-title a").attr("href"); const price = $(elem).find(".z-highlight").text(); return { title: altText + " " + price, link, description: $(elem).find(".feed-block-descripe").text().replaceAll(/\s+/g, "") }; }); return { title, link, item: (await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const $ = load(await ofetch_default(item.link, { headers: getHeaders() })); if ($("span.old").length > 0) return null; else { item.pubDate = $("meta[name=\"weibo:webpage:create_at\"]").attr("content"); if (item.description === "阅读全文") item.description = $("p[itemprop=\"description\"]").first().html(); return item; } })))).filter((result) => result !== null) }; } //#endregion export { route };