UNPKG

rsshub

Version:
258 lines (257 loc) 5 kB
import { t as config } from "./config-CCmw1BNE.mjs"; import "./types-DNj6Etbg.mjs"; import { t as got_default } from "./got-BTowW50G.mjs"; import { t as timezone } from "./timezone-BBvDwS_3.mjs"; import { t as ConfigNotFoundError } from "./config-not-found-fQ5mxvDU.mjs"; import { t as getHeaders } from "./utils-BcgNHOwm.mjs"; //#region lib/routes/smzdm/ranking.ts const getTrueHour = (rank_type, rank_id, hour) => { const rank_two_hour = [ "11", "17", "28", "29" ]; const rank_four_hour = [ "12", "13", "14", "15", "17", "74", "75", "71", "25" ]; if (["pinlei", "dianshang"].includes(rank_type) && [...rank_two_hour, ...rank_four_hour].includes(rank_id) && hour === "3") return rank_two_hour.includes(rank_id) ? "2" : "4"; return hour; }; const typeOptions = [ { value: "pinlei", label: "好价品类榜" }, { value: "dianshang", label: "好价电商榜" }, { value: "haitao", label: "海淘 TOP 榜" }, { value: "haowen", label: "好文排行榜" }, { value: "haowu", label: "好物排行榜" } ]; const idOptions = [ { label: "好价品类榜-全部", value: "11" }, { label: "好价品类榜-食品生鲜", value: "12" }, { label: "好价品类榜-电脑数码", value: "13" }, { label: "好价品类榜-运动户外", value: "14" }, { label: "好价品类榜-家用电器", value: "15" }, { label: "好价品类榜-白菜", value: "17" }, { label: "好价品类榜-服饰鞋包", value: "74" }, { label: "好价品类榜-日用百货", value: "75" }, { label: "好价电商榜-券活动", value: "24" }, { label: "好价电商榜-京东", value: "23" }, { label: "好价电商榜-天猫", value: "25" }, { label: "好价电商榜-亚马逊中国", value: "26" }, { label: "好价电商榜-国美在线", value: "27" }, { label: "好价电商榜-苏宁易购", value: "28" }, { label: "好价电商榜-网易", value: "29" }, { label: "好价电商榜-西集网", value: "30" }, { label: "好价电商榜-美国亚马逊", value: "31" }, { label: "好价电商榜-日本亚马逊", value: "32" }, { label: "好价电商榜-ebay", value: "33" }, { label: "海淘 TOP 榜-全部", value: "39" }, { label: "海淘 TOP 榜-海外直邮", value: "34" }, { label: "海淘 TOP 榜-美国榜", value: "35" }, { label: "海淘 TOP 榜-欧洲榜", value: "36" }, { label: "海淘 TOP 榜-澳新榜", value: "37" }, { label: "海淘 TOP 榜-亚洲榜", value: "38" }, { label: "海淘 TOP 榜-晒物榜", value: "hsw" }, { label: "好文排行榜-原创", value: "yc" }, { label: "好文排行榜-资讯", value: "zx" }, { label: "好物排行榜-新晋榜", value: "hwall" }, { label: "好物排行榜-消费众测", value: "zc" }, { label: "好物排行榜-新锐品牌", value: "nb" }, { label: "好物排行榜-好物榜单", value: "hw" } ]; const route = { path: "/ranking/:rank_type/:rank_id/:hour", categories: ["shopping"], view: 5, example: "/smzdm/ranking/pinlei/11/3", parameters: { rank_type: { description: "榜单类型", options: typeOptions }, rank_id: { description: "榜单ID", options: idOptions }, hour: { description: "时间跨度", options: [ { value: "3", label: "3 小时" }, { value: "12", label: "12 小时" }, { value: "24", label: "24 小时" } ] } }, features: { requireConfig: [{ name: "SMZDM_COOKIE", description: "什么值得买登录后的 Cookie 值" }], requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "排行榜", maintainers: ["DIYgod"], handler }; async function handler(ctx) { if (!config.smzdm.cookie) throw new ConfigNotFoundError("什么值得买排行榜 is disabled due to the lack of SMZDM_COOKIE"); const { rank_type, rank_id, hour } = ctx.req.param(); const true_hour = getTrueHour(rank_type, rank_id, hour); const data = (await got_default("https://www.smzdm.com/top/json_more", { headers: { Referer: "https://www.smzdm.com/top", ...getHeaders() }, searchParams: { rank_type, rank_id, hour: true_hour } })).data.data.list.slice(0, 6); const list = [...data.map((row) => row[0]), ...data.map((row) => row[1])].filter((item) => item.length !== 0); return { title: `什么值得买${typeOptions.find((item) => item.value === rank_type)?.label}-${idOptions.find((item) => item.value === rank_id)?.label}-${hour}小时`, link: "https://www.smzdm.com/top/", allowEmpty: true, item: list.map((item) => ({ title: `${item.article_title} - ${item.article_price}`, description: `${item.article_title} - ${item.article_price}<br><img src="${item.article_pic}">`, pubDate: timezone(item.article_pubdate, 8), link: item.article_url })) }; } //#endregion export { route };