feat: New Router for liveuamap (#14175)

* Added new route for liveuamap

* Fix unsafe domain and the 3rd level domain defaulting

* docs: fix heading

---------
This commit is contained in:
Jon Hao
2024-01-06 00:36:50 +08:00
committed by GitHub
parent 008fcaea83
commit 16d4e5932b
5 changed files with 66 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { isValidHost } = require('@/utils/valid-host');
module.exports = async (ctx) => {
let region = ctx.params.region ?? 'ukraine';
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 50;
if (!isValidHost(region)) {
throw Error('Invalid region');
}
let url = `https://${region}.liveuamap.com/`;
if (region === undefined) {
region = 'Default';
url = 'https://liveuamap.com/';
}
const response = await got({
method: 'get',
url,
});
const $ = cheerio.load(response.data);
const items = $('div#feedler > div')
.slice(0, limit)
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('div.title').text(),
description: item.find('div.title').text(),
link: item.attr('data-link'),
};
});
ctx.state.data = {
title: `Liveuamap - ${region}`,
link: url,
item: items,
};
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/:region?': ['CoderSherlock'],
};
+13
View File
@@ -0,0 +1,13 @@
module.exports = {
'liveuamap.com': {
_name: 'Live Universal Awareness Map',
'.': [
{
title: 'Region',
docs: 'https://docs.rsshub.app/routes/new-media#live-universal-awareness-map',
source: ['/:region*'],
target: '/liveuamap/:region',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:region?', require('./'));
};
+6
View File
@@ -910,6 +910,12 @@
<Route author="TonyRL" example="/line/today/th/publisher/101048" path="/line/today/:edition/publisher/:id" paramsDesc={['Edition, see table above', 'Channel ID, can be found in URL']} radar="1" />
## Live Universal Awareness Map {#live-universal-awareness-map}
### 实时消息 {#live-universal-awareness-map-shi-shi-xiao-xi}
<Route author="CoderSherlock" example="/liveuamap" path="/liveuamap/:region?" paramsDesc={['region 热点地区,默认为`ukraine`,其他选项见liveuamap.com的三级域名']} anticrawler="1" />
## LVV2 {#lvv2}
### 频道 {#lvv2-pin-dao}