/
post.ts
71 lines (62 loc) 路 2.19 KB
/
post.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
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';
import { appsUrl, newsUrl, fixImg } from '../utils';
export const route: Route = {
path: '/apps/:lang?/post/:id',
categories: ['anime'],
example: '/qoo-app/apps/en/post/7675',
parameters: { lang: 'Language, see the table above, empty means `涓枃`', id: 'Game ID, can be found in URL' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: 'Game Store - Article',
maintainers: ['TonyRL'],
handler,
};
async function handler(ctx) {
const { id, lang = '' } = ctx.req.param();
const link = `${appsUrl}${lang ? `/${lang}` : ''}/app-post/${id}`;
const { data: response } = await got(link);
const $ = load(response);
const list = $('.qoo-post-item')
.toArray()
.map((item) => {
item = $(item);
const a = item.find('a');
return {
title: a.attr('title'),
link: a.attr('href'),
// description: item.find('.img-list').html() + item.find('.text-view').html(),
pubDate: timezone(parseDate(item.find('time').text(), 'YYYY-MM-DD HH:mm'), 8),
author: item.find('cite.name').text(),
postId: a.attr('href').split('/').pop(),
};
});
const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const { data } = await got(`${newsUrl}${lang ? `/${lang}` : ''}/wp-json/wp/v2/posts/${item.postId}`);
const $ = load(data.content.rendered, null, false);
fixImg($);
item.description = $.html();
item.pubDate = parseDate(data.date_gmt);
return item;
})
)
);
return {
title: $('head title').text(),
link,
language: $('html').attr('lang'),
item: items,
};
}