Skip to content

Commit

Permalink
feat: New Router for liveuamap (#14175)
Browse files Browse the repository at this point in the history
* Added new route for liveuamap

* Fix unsafe domain and the 3rd level domain defaulting

* docs: fix heading

---------
  • Loading branch information
CoderSherlock authored Jan 5, 2024
1 parent 008fcae commit 16d4e59
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
41 changes: 41 additions & 0 deletions lib/v2/liveuamap/index.js
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions lib/v2/liveuamap/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/:region?': ['CoderSherlock'],
};
13 changes: 13 additions & 0 deletions lib/v2/liveuamap/radar.js
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions lib/v2/liveuamap/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:region?', require('./'));
};
6 changes: 6 additions & 0 deletions website/docs/routes/new-media.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 16d4e59

Please sign in to comment.