UNPKG

rsshub

Version:
147 lines (144 loc) • 5.14 kB
import "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import { t as ViewType } from "./types-D84BRIt4.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import * as cheerio from "cheerio"; //#region lib/routes/binance/announcement.ts const ROUTE_PARAMETERS_CATALOGID_MAPPING = { "new-cryptocurrency-listing": 48, "latest-binance-news": 49, "latest-activities": 93, "new-fiat-listings": 50, "api-updates": 51, "crypto-airdrop": 128, "wallet-maintenance-updates": 157, delisting: 161 }; function assertAnnouncementsConfig(playlist) { if (!playlist || typeof playlist !== "object") return false; if (!("reactRoot" in playlist)) return false; if (!Array.isArray(playlist.reactRoot)) return false; if (playlist.reactRoot?.[0]?.id !== "Fragment") return false; return true; } function assertAnnouncementsConfigList(props) { if (!props || typeof props !== "object") return false; if (!("config" in props)) return false; if (!("list" in props.config)) return false; return true; } const handler = async (ctx) => { const baseUrl = "https://www.binance.com"; const announcementCategoryUrl = `${baseUrl}/support/announcement`; const { type } = ctx.req.param(); const language = ctx.req.header("Accept-Language"); const headers = { Referer: baseUrl, "Accept-Language": language ?? "en-US,en;q=0.9" }; const announcementsConfig = await cache_default.tryGet(`binance:announcements:${language}`, async () => { const announcementRes = await ofetch_default(announcementCategoryUrl, { headers }); const $$1 = cheerio.load(announcementRes); const appData$1 = JSON.parse($$1("#__APP_DATA").text()); const announcements = Object.values(appData$1.appState.loader.dataByRouteId).find((value) => "playlist" in value); if (!assertAnnouncementsConfig(announcements.playlist)) throw new Error("Get announcement config failed"); const listConfigProps = announcements.playlist.reactRoot[0].children.find((i) => i.id === "TopicCardList")?.props; if (!assertAnnouncementsConfigList(listConfigProps)) throw new Error("Can't get announcement config list"); return listConfigProps.config.list; }); const announcementCatalogId = ROUTE_PARAMETERS_CATALOGID_MAPPING[type]; if (!announcementCatalogId) throw new Error(`${type} is not supported`); const targetItem = announcementsConfig.find((i) => i.url.includes(`c-${announcementCatalogId}`)); if (!targetItem) throw new Error("Unexpected announcements config"); const link = new URL(targetItem.url, baseUrl).toString(); const response = await ofetch_default(link, { headers }); const $ = cheerio.load(response); const appData = JSON.parse($("#__APP_DATA").text()); const catalog = Object.values(appData.appState.loader.dataByRouteId).find((value) => "catalogs" in value).catalogs.find((catalog$1) => catalog$1.catalogId === announcementCatalogId); const item = await Promise.all(catalog.articles.map((i) => { const link$1 = `${announcementCategoryUrl}/${i.code}`; const item$1 = { title: i.title, link: link$1, description: i.title, pubDate: parseDate(i.releaseDate) }; return cache_default.tryGet(`binance:announcement:${i.code}:${language}`, async () => { const res = await ofetch_default(link$1, { headers }); const descriptionEl = cheerio.load(res)("#support_article > div").first(); descriptionEl.find("style").remove(); item$1.description = descriptionEl.html() ?? ""; return item$1; }); })); return { title: targetItem.title, link, description: targetItem.description, item }; }; const route = { path: "/announcement/:type", categories: ["finance"], view: ViewType.Articles, example: "/binance/announcement/new-cryptocurrency-listing", parameters: { type: { description: "Binance Announcement type", default: "new-cryptocurrency-listing", options: [ { value: "new-cryptocurrency-listing", label: "New Cryptocurrency Listing" }, { value: "latest-binance-news", label: "Latest Binance News" }, { value: "latest-activities", label: "Latest Activities" }, { value: "new-fiat-listings", label: "New Fiat Listings" }, { value: "api-updates", label: "API Updates" }, { value: "crypto-airdrop", label: "Crypto Airdrop" }, { value: "wallet-maintenance-updates", label: "Wallet Maintenance Updates" }, { value: "delisting", label: "Delisting" } ] } }, name: "Announcement", description: ` Type category - new-cryptocurrency-listing => New Cryptocurrency Listing - latest-binance-news => Latest Binance News - latest-activities => Latest Activities - new-fiat-listings => New Fiat Listings - api-updates => API Updates - crypto-airdrop => Crypto Airdrop - wallet-maintenance-updates => Wallet Maintenance Updates - delisting => Delisting `, maintainers: ["enpitsulin"], handler }; //#endregion export { route };