diff --git a/lib/routes/bangumi/tv/other/followrank.ts b/lib/routes/bangumi/tv/other/followrank.ts index 5175ca995..3271ac28a 100644 --- a/lib/routes/bangumi/tv/other/followrank.ts +++ b/lib/routes/bangumi/tv/other/followrank.ts @@ -1,12 +1,13 @@ import { Route } from '@/types'; -import got from '@/utils/got'; import { load } from 'cheerio'; import { config } from '@/config'; +import ofetch from '@/utils/ofetch'; + export const route: Route = { - path: '/tv/followrank', + path: '/:type/followrank', categories: ['anime'], - example: '/bangumi/tv/followrank', - parameters: {}, + example: '/bangumi/anime/followrank', + parameters: { type: '类型:anime - 动画, book - 图书, music - 音乐, game - 游戏, real - 三次元' }, features: { requireConfig: false, requirePuppeteer: false, @@ -17,26 +18,29 @@ export const route: Route = { }, radar: [ { - source: ['bgm.tv/anime'], + source: ['bgm.tv/:type'], + target: '/:type/followrank', }, ], - name: '成员关注动画榜', - maintainers: ['honue'], + name: '成员关注榜', + maintainers: ['honue', 'zhoukuncheng'], handler, - url: 'bgm.tv/anime', }; -async function handler() { - const url = 'https://bgm.tv/anime'; - const response = await got({ - url, - method: 'get', +async function handler(ctx) { + let type = ctx.req.param('type'); + if (!type || type === 'tv') { + type = 'anime'; + } + const url = `https://bgm.tv/${type}`; + + const response = await ofetch(url, { headers: { 'User-Agent': config.trueUA, }, }); - const $ = load(response.body); + const $ = load(response); const items = [ ...$('#columnB > div:nth-child(4) > table > tbody') @@ -58,10 +62,19 @@ async function handler() { })), ]; + const RANK_TYPES = { + tv: '动画', + anime: '动画', + book: '图书', + music: '音乐', + game: '游戏', + real: '三次元', + }; + return { - title: 'Bangumi 成员关注动画榜', + title: `BangumiTV 成员关注${RANK_TYPES[type]}榜`, link: url, item: items, - description: `Bangumi 首页-成员关注动画榜`, + description: `BangumiTV 首页-成员关注${RANK_TYPES[type]}榜`, }; }