UNPKG

rsshub

Version:
40 lines (39 loc) 1.4 kB
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs"; import { t as isValidHost } from "./valid-host-BhcFf8dN.mjs"; import { load } from "cheerio"; //#region lib/routes/booth.pm/shop.ts const route = { path: "/shop/:subdomain", categories: ["shopping"], example: "/booth.pm/shop/annn-boc0123", parameters: { subdomain: "Shop subdomain" }, name: "Shop", maintainers: ["KTachibanaM"], handler }; async function handler(ctx) { const { subdomain } = ctx.req.param(); if (!isValidHost(subdomain)) throw new Error("Invalid subdomain"); const shopUrl = `https://${subdomain}.booth.pm`; const $ = load(await rofetch(`${shopUrl}/items`, { headers: { cookie: "adult=t" } })); const shopName = $("div.shop-name > span").text(); const items = $("li.js-mount-point-shop-item-card").toArray().map((element) => { const item = JSON.parse($(element).attr("data-item")); return { title: item.name, description: item.thumbnail_image_urls.map((url) => `<img src="${url.replace(/\/c\/[^/]+\//, "/").replace("_base_resized", "")}">`).join(""), link: item.shop_item_url, category: [item.category.name.en, item.category.name.ja] }; }); return { title: shopName, link: shopUrl, description: $(".booth-description > div > div").first().text(), image: $(".avatar-image").attr("style")?.match(/url\((.*?)\)/)?.[1], allowEmpty: true, item: items }; } //#endregion export { route };