* feat(route): add route "BaoBua" * perf(route/baobua): cache paginated content to reduce API requests * Revert "perf(route/baobua): cache paginated content to reduce API requests" This reverts commit 200616c15ae173ef4882da92fd7aec48dcffefda. * feat(route): add route "BaoBua"
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import { Route } from '@/types';
|
|
import cache from '@/utils/cache';
|
|
import got from '@/utils/got';
|
|
import { load } from 'cheerio';
|
|
import { SUB_NAME_PREFIX, SUB_URL } from './const';
|
|
import loadArticle from './article';
|
|
|
|
export const route: Route = {
|
|
path: '/category/:category',
|
|
categories: ['picture'],
|
|
example: '/baobua/category/network',
|
|
parameters: { category: 'Category' },
|
|
features: {
|
|
requireConfig: false,
|
|
requirePuppeteer: false,
|
|
antiCrawler: false,
|
|
supportBT: false,
|
|
supportPodcast: false,
|
|
supportScihub: false,
|
|
},
|
|
radar: [
|
|
{
|
|
source: ['baobua.com/cat/:category'],
|
|
target: '/category/:category',
|
|
},
|
|
],
|
|
name: 'Category',
|
|
maintainers: ['AiraNadih'],
|
|
handler,
|
|
url: 'baobua.com/',
|
|
};
|
|
|
|
async function handler(ctx) {
|
|
const category = ctx.req.param('category');
|
|
const url = `${SUB_URL}cat/${category}/`;
|
|
|
|
const response = await got(url);
|
|
const $ = load(response.body);
|
|
const itemRaw = $('.thcovering-video').toArray();
|
|
|
|
return {
|
|
title: `${SUB_NAME_PREFIX} - Category: ${category}`,
|
|
link: url,
|
|
item: await Promise.all(
|
|
itemRaw
|
|
.map((e) => {
|
|
const item = $(e);
|
|
let link = item.find('a').attr('href');
|
|
if (!link) {
|
|
return null;
|
|
}
|
|
if (link.startsWith('/')) {
|
|
link = new URL(link, SUB_URL).href;
|
|
}
|
|
return cache.tryGet(link, () => loadArticle(link));
|
|
})
|
|
.filter(Boolean)
|
|
),
|
|
};
|
|
}
|