UNPKG

rsshub

Version:
66 lines (64 loc) 2.46 kB
import "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import "./cache-Bo__VnGm.mjs"; import { t as appstoreBearerToken } from "./utils-YYSno34i.mjs"; import { load } from "cheerio"; //#region lib/routes/appstore/in-app-purchase.ts const route = { path: "/iap/:country/:id", categories: ["program-update"], example: "/appstore/iap/us/id953286746", parameters: { country: "App Store Country, obtain from the app URL https://apps.apple.com/us/app/id953286746, in this case, `us`", id: "App Store app id, obtain from the app URL https://apps.apple.com/us/app/id953286746, in this case, `id953286746`" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "In-App-Purchase Price Drop Alert", maintainers: ["HenryQW"], handler }; async function handler(ctx) { const country = ctx.req.param("country"); const id = ctx.req.param("id"); const link = `https://apps.apple.com/${country}/app/${id}`; const lang = load(await ofetch_default(link))("html").attr("lang"); const mediaToken = await appstoreBearerToken(); const appData = (await ofetch_default(`https://amp-api-edge.apps.apple.com/v1/catalog/${country}/apps/${id.replace("id", "")}`, { headers: { authorization: `Bearer ${mediaToken}`, origin: "https://apps.apple.com" }, query: { platform: "web", include: "merchandised-in-apps,top-in-apps,eula", l: lang } })).data[0]; const attributes = appData.attributes; const platform = attributes.deviceFamilies.includes("mac") ? "macOS" : "iOS"; let item = []; const iap = appData.relationships["top-in-apps"].data; if (iap) item = iap.map(({ attributes: attributes$1 }) => ({ title: `${attributes$1.name} is now ${attributes$1.offers[0].priceFormatted}`, link: attributes$1.url, guid: `${attributes$1.url}:${attributes$1.offerName}:${attributes$1.offers[0].priceString}`, description: attributes$1.artwork ? attributes$1.description.standard + `<br><img src=${attributes$1.artwork.url.replace("{w}x{h}{c}.{f}", "3000x3000bb.webp")}>` : attributes$1.description.standard })); return { title: `${country.toLowerCase() === "cn" ? "内购限免提醒" : "IAP price watcher"}: ${attributes.name} for ${platform}`, link, item }; } //#endregion export { route };