UNPKG

rsshub

Version:
50 lines (49 loc) 1.78 kB
import { t as got_default } from "./got-BTowW50G.mjs"; import { n as processItems, r as rootUrl, t as getData } from "./util-4-Rgl4Aq.mjs"; //#region lib/routes/xinpianchang/rank.ts const route = { path: "/rank/:category?", categories: ["new-media"], example: "/xinpianchang/rank", parameters: { category: "分类 id,可在对应排行榜页 URL 中找到,见下表,默认为 `all` ,即总榜" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "排行榜", maintainers: ["nczitzk"], handler, description: `| 分类 | id | | -------- | ---------- | | 总榜 | all | | 精选榜 | staffPicks | | 广告 | ad | | 宣传片 | publicity | | 创意 | creative | | 干货教程 | backstage |` }; async function handler(ctx) { const { category = "all" } = ctx.req.param(); const limit = ctx.req.query("limit") ? Number(ctx.req.query("limit")) : 60; const apiRankUrl = new URL(`api/xpc/v2/rank/${category}`, rootUrl).href; const { data: apiResponse } = await got_default(apiRankUrl); const current = apiResponse.data.list[0]; const currentUrl = current.web_link; const currentName = `${current.code}-${current.year}-${current.index}`; const { data, response: currentResponse } = await getData(currentUrl); const buildId = currentResponse.match(/\/static\/(\w+)\/_buildManifest\.js/)[1]; const apiUrl = new URL(`_next/data/${buildId}/rank/article/${currentName}.json`, rootUrl).href; const { data: response } = await got_default(apiUrl); let items = response.pageProps.rankList; items = await processItems(items.slice(0, limit)); return { ...data, item: items }; } //#endregion export { route };