/
timeline.ts
85 lines (76 loc) · 2.6 KB
/
timeline.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { Route } from '@/types';
import { getCurrentPath } from '@/utils/helpers';
const __dirname = getCurrentPath(import.meta.url);
import cache from '@/utils/cache';
import got from '@/utils/got';
import timezone from '@/utils/timezone';
import { parseDate } from '@/utils/parse-date';
import { art } from '@/utils/render';
import path from 'node:path';
import MarkdownIt from 'markdown-it';
const md = MarkdownIt({
html: true,
});
export const route: Route = {
path: '/timeline',
categories: ['new-media'],
example: '/utgd/timeline',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['utgd.net/'],
},
],
name: '时间线',
maintainers: ['nczitzk'],
handler,
url: 'utgd.net/',
};
async function handler(ctx) {
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 20;
const rootUrl = 'https://utgd.net';
const apiUrl = `${rootUrl}/api/v2/timeline/?page=1&page_size=${limit}`;
const response = await got({
method: 'get',
url: apiUrl,
});
const items = await Promise.all(
response.data.results.slice(0, limit).map((item) =>
cache.tryGet(`untag-${item.id}`, async () => {
const detailResponse = await got({
method: 'get',
url: `${rootUrl}/api/v2/article/${item.id}/`,
searchParams: {
fields: 'article_description,article_category(category_name),article_tag(tag_name)',
},
});
const data = detailResponse.data;
return {
title: item.title,
link: `${rootUrl}/article/${item.id}`,
description: art(path.join(__dirname, 'templates/description.art'), {
membership: data.article_for_membership,
image: item.article_image,
description: md.render(data.article_description),
}),
author: item.article_author_displayname,
pubDate: timezone(parseDate(item.article_published_time), +8),
category: [...data.article_category.map((c) => c.category_name), ...data.article_tag.map((t) => t.tag_name)],
};
})
)
);
return {
title: 'UNTAG',
link: rootUrl,
item: items,
};
}