/
cat.ts
38 lines (37 loc) 路 1.12 KB
/
cat.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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: '/cat/:cat{.+}?',
radar: [
{
source: ['8kcosplay.com/'],
target: '',
},
],
name: 'Unknown',
maintainers: [],
handler,
url: '8kcosplay.com/',
};
async function handler(ctx) {
const limit = Number.parseInt(ctx.req.query('limit'));
const { cat = '8kasianidol' } = ctx.req.param();
const url = `${SUB_URL}category/${cat}/`;
const resp = await got(url);
const $ = load(resp.body);
const itemRaw = $('li.item').toArray();
return {
title: `${SUB_NAME_PREFIX}-${$('span[property=name]:not(.hide)').text()}`,
link: url,
item: await Promise.all(
(limit ? itemRaw.slice(0, limit) : itemRaw).map((e) => {
const { href } = load(e)('h2 > a')[0].attribs;
return cache.tryGet(href, () => loadArticle(href));
})
),
};
}