From 16d4e5932ba6a265ffc4787a6f8aca4bf8152bd0 Mon Sep 17 00:00:00 2001 From: Jon Hao Date: Fri, 5 Jan 2024 08:36:50 -0800 Subject: [PATCH] feat: New Router for liveuamap (#14175) * Added new route for liveuamap * Fix unsafe domain and the 3rd level domain defaulting * docs: fix heading --------- --- lib/v2/liveuamap/index.js | 41 +++++++++++++++++++++++++++++++ lib/v2/liveuamap/maintainer.js | 3 +++ lib/v2/liveuamap/radar.js | 13 ++++++++++ lib/v2/liveuamap/router.js | 3 +++ website/docs/routes/new-media.mdx | 6 +++++ 5 files changed, 66 insertions(+) create mode 100644 lib/v2/liveuamap/index.js create mode 100644 lib/v2/liveuamap/maintainer.js create mode 100644 lib/v2/liveuamap/radar.js create mode 100644 lib/v2/liveuamap/router.js diff --git a/lib/v2/liveuamap/index.js b/lib/v2/liveuamap/index.js new file mode 100644 index 00000000000000..229fb2337557a9 --- /dev/null +++ b/lib/v2/liveuamap/index.js @@ -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, + }; +}; diff --git a/lib/v2/liveuamap/maintainer.js b/lib/v2/liveuamap/maintainer.js new file mode 100644 index 00000000000000..f4c914280bca00 --- /dev/null +++ b/lib/v2/liveuamap/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:region?': ['CoderSherlock'], +}; diff --git a/lib/v2/liveuamap/radar.js b/lib/v2/liveuamap/radar.js new file mode 100644 index 00000000000000..3610c00fb16602 --- /dev/null +++ b/lib/v2/liveuamap/radar.js @@ -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', + }, + ], + }, +}; diff --git a/lib/v2/liveuamap/router.js b/lib/v2/liveuamap/router.js new file mode 100644 index 00000000000000..e540ed9baad4b9 --- /dev/null +++ b/lib/v2/liveuamap/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/:region?', require('./')); +}; diff --git a/website/docs/routes/new-media.mdx b/website/docs/routes/new-media.mdx index 49ae0b4408bb2c..02fd7947f2b0d9 100644 --- a/website/docs/routes/new-media.mdx +++ b/website/docs/routes/new-media.mdx @@ -910,6 +910,12 @@ +## Live Universal Awareness Map {#live-universal-awareness-map} + +### 实时消息 {#live-universal-awareness-map-shi-shi-xiao-xi} + + + ## LVV2 {#lvv2} ### 频道 {#lvv2-pin-dao}