/
research.ts
51 lines (44 loc) 路 1.26 KB
/
research.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 got from '@/utils/got';
import { getApiUrl, parseArticle } from './common';
export const route: Route = {
path: '/research',
categories: ['new-media'],
example: '/openai/research',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: 'Research',
maintainers: ['yuguorui'],
handler,
};
async function handler(ctx) {
const apiUrl = new URL('/api/v1/research-publications', await getApiUrl());
const researchRootUrl = 'https://openai.com/research';
// Construct API query
apiUrl.searchParams.append('sort', '-publicationDate,-createdAt');
apiUrl.searchParams.append('include', 'media');
const resp = await got({
method: 'get',
url: apiUrl,
});
const obj = resp.data;
const items = await Promise.all(
obj.data.map((item) => {
const attributes = item.attributes;
return parseArticle(ctx, researchRootUrl, attributes);
})
);
const title = 'OpenAI Research';
return {
title,
link: researchRootUrl,
item: items,
};
}