UNPKG

rsshub

Version:
67 lines (64 loc) 2.21 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 "./ofetch-BIyrKU3Y.mjs"; import "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import "./helpers-DxBp0Pty.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { t as invalid_parameter_default } from "./invalid-parameter-rr4AgGpp.mjs"; import { r as getPlurk, t as baseUrl } from "./utils-D-b2Mbgt.mjs"; //#region lib/routes/plurk/top.ts const categoryList = new Set([ "topReplurks", "topFavorites", "topResponded" ]); const route = { path: "/top/:category?/:lang?", categories: ["social-media"], view: ViewType.SocialMedia, example: "/plurk/top/topReplurks", parameters: { category: "Category, see the table below, `topReplurks` by default", lang: "Language, see the table below, `en` by default" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "Top", maintainers: ["TonyRL"], handler, description: `| Top Replurks | Top Favorites | Top Responded | | ------------ | ------------- | ------------- | | topReplurks | topFavorites | topResponded | | English | 中文(繁體) | | ------- | ------------ | | en | zh |` }; async function handler(ctx) { const { category = "topReplurks", lang = "en" } = ctx.req.param(); if (!categoryList.has(category)) throw new invalid_parameter_default(`Invalid category: ${category}`); const { data: apiResponse } = await got_default(`${baseUrl}/Stats/${category}`, { searchParams: { period: "day", lang, limit: ctx.req.query("limit") ? Number(ctx.req.query("limit")) : 90 } }); const items = await Promise.all(apiResponse.stats.map((item) => item[1]).map((item) => getPlurk(`plurk:${item.plurk_id}`, item, item.owner.display_name, cache_default.tryGet))); return { title: "Top Plurk - Plurk", image: "https://s.plurk.com/2c1574c02566f3b06e91.png", link: `${baseUrl}/top#${category}`, item: items, language: lang }; } //#endregion export { route };