UNPKG

rsshub

Version:
67 lines (64 loc) 2.21 kB
import "./dist-Bog6z_OM.mjs"; import "./config-MQ-7ebJ_.mjs"; import { t as ViewType } from "./types-gOySfSXJ.mjs"; import "./logger-C4avouvV.mjs"; import "./ofetch-DKl_Ma9g.mjs"; import "./parse-date-r5WDWHno.mjs"; import "./is-worker-DESPicPc.mjs"; import { t as cache_default } from "./cache-SV6W5EPy.mjs"; import "./helpers-Bo4JQYdN.mjs"; import { t as got_default } from "./got-CO-ndVl2.mjs"; import { t as invalid_parameter_default } from "./invalid-parameter-ByDtry1B.mjs"; import { r as getPlurk, t as baseUrl } from "./utils-LeZkcvgG.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 };