-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: New Router for liveuamap (#14175)
* Added new route for liveuamap * Fix unsafe domain and the 3rd level domain defaulting * docs: fix heading ---------
- Loading branch information
1 parent
008fcae
commit 16d4e59
Showing
5 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'/:region?': ['CoderSherlock'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = (router) => { | ||
router.get('/:region?', require('./')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters