rsshub
Version:
Make RSS Great Again!
60 lines (58 loc) • 2.16 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.mjs";
import "./render-BQo6B4tL.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import { n as processItems, r as rootUrl, t as getData } from "./util-c_F5q-vl.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.parseInt(ctx.req.query("limit"), 10) : 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, cache_default.tryGet);
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), cache_default.tryGet);
return {
...data,
item: items
};
}
//#endregion
export { route };