/
software.ts
59 lines (54 loc) 路 1.97 KB
/
software.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
import { Route } from '@/types';
import cache from '@/utils/cache';
import { baseURL, puppeteerGet } from './utils';
import { load } from 'cheerio';
export const route: Route = {
path: '/software/:name/:routeParams?',
categories: ['programming'],
example: '/alternativeto/software/cpp',
parameters: { name: 'Software name', routeParams: 'Filters of software type' },
features: {
requireConfig: false,
requirePuppeteer: true,
antiCrawler: true,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['www.alternativeto.net/software/:name'],
target: '/software/:name',
},
],
name: 'Software Alternatives',
maintainers: ['JimenezLi'],
handler,
description: `> routeParms can be copied from original site URL, example: \`/alternativeto/software/cpp/license=opensource&platform=windows\``,
};
async function handler(ctx) {
const name = ctx.req.param('name');
const query = new URLSearchParams(ctx.req.param('routeParams'));
const link = `https://alternativeto.net/software/${name}/?${query.toString()}`;
// use Puppeteer due to the obstacle by cloudflare challenge
const html = await puppeteerGet(link, cache);
const $ = load(html);
return {
title: $('.Heading_h1___Cf5Y').text().trim(),
description: $('.intro-text').text().trim(),
link,
item: $('.AppListItem_appInfo__h9cWP')
.toArray()
.map((element) => {
const item = $(element);
const title = item.find('.Heading_h2___LwQD').text().trim();
const link = `${baseURL}${item.find('.Heading_h2___LwQD a').attr('href')}`;
const description = item.find('.AppListItem_description__wtODK').text().trim();
return {
title,
link,
description,
};
}),
};
}