/
label.ts
43 lines (38 loc) · 1.18 KB
/
label.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
39
40
41
42
43
import { Route } from '@/types';
import cache from '@/utils/cache';
import { rootUrl, apiRootUrl, processItems, getInfo } from './util';
export const route: Route = {
path: '/label/:name',
categories: ['new-media'],
example: '/cyzone/label/创业邦周报',
parameters: { name: '标签名称,可在对应标签页 URL 中找到' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['cyzone.cn/label/:name', 'cyzone.cn/'],
},
],
name: '标签',
maintainers: ['nczitzk'],
handler,
};
async function handler(ctx) {
const name = ctx.req.param('name');
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 5;
const apiUrl = new URL('v2/content/tag/tagList', apiRootUrl).href;
const currentUrl = new URL(`label/${name}`, rootUrl).href;
const items = await processItems(apiUrl, limit, cache.tryGet, {
tag: name,
});
return {
item: items,
...(await getInfo(currentUrl, cache.tryGet)),
};
}