/
moment.ts
51 lines (43 loc) 路 1.25 KB
/
moment.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
44
45
46
47
48
49
50
51
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { rootUrl, apiMomentRootUrl, processItems, fetchData } from './util';
export const route: Route = {
path: '/moment',
categories: ['new-media'],
example: '/huxiu/moment',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: true,
supportPodcast: true,
supportScihub: false,
},
radar: [
{
source: ['huxiu.com/moment'],
},
],
name: '24 灏忔椂',
maintainers: ['nczitzk'],
handler,
url: 'huxiu.com/moment',
};
async function handler(ctx) {
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 20;
const apiUrl = new URL('web-v2/moment/feed', apiMomentRootUrl).href;
const currentUrl = new URL('moment', rootUrl).href;
const { data: response } = await got.post(apiUrl, {
form: {
platform: 'www',
},
});
const items = await processItems(response.data.moment_list.datalist[0].datalist, limit, cache.tryGet);
const data = await fetchData(currentUrl);
return {
item: items,
...data,
};
}