From 5c694e35b38b1a400cf9ebebaa6a0d0fa9bf6e68 Mon Sep 17 00:00:00 2001 From: Fatpandac <1779196284@qq.com> Date: Wed, 23 Feb 2022 20:11:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20EMS=20=E8=8B=B9=E6=9E=9C?= =?UTF-8?q?=E9=82=AE=E4=BB=B6=20and=20refactor=20to=20V2=20(#9175)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/other.md | 8 +++++++ lib/radar-rules.js | 11 --------- lib/router.js | 3 --- lib/v2/ems/apple.js | 42 ++++++++++++++++++++++++++++++++++ lib/v2/ems/maintainer.js | 4 ++++ lib/{routes => v2}/ems/news.js | 0 lib/v2/ems/radar.js | 19 +++++++++++++++ lib/v2/ems/router.js | 4 ++++ lib/v2/ems/templates/apple.art | 6 +++++ 9 files changed, 83 insertions(+), 14 deletions(-) create mode 100644 lib/v2/ems/apple.js create mode 100644 lib/v2/ems/maintainer.js rename lib/{routes => v2}/ems/news.js (100%) create mode 100644 lib/v2/ems/radar.js create mode 100644 lib/v2/ems/router.js create mode 100644 lib/v2/ems/templates/apple.art diff --git a/docs/other.md b/docs/other.md index f815b74cd..83031aff7 100644 --- a/docs/other.md +++ b/docs/other.md @@ -54,6 +54,10 @@ pageClass: routes +### 苹果邮件 + +见 [#中国邮政速递物流](/other.html#zhong-guo-you-zheng-su-di-wu-liu) + ### App Store/Mac App Store 见 [#app-store-mac-app-store](/program-update.html#app-store-mac-app-store) @@ -1055,6 +1059,10 @@ type 为 all 时,category 参数不支持 cost 和 free +### 苹果邮件 + + + ## 自如 ### 房源 diff --git a/lib/radar-rules.js b/lib/radar-rules.js index 6b9e2487c..dcd9d9662 100644 --- a/lib/radar-rules.js +++ b/lib/radar-rules.js @@ -2095,17 +2095,6 @@ module.exports = { }, ], }, - 'ems.com.cn': { - _name: '中国邮政速递物流', - www: [ - { - title: '新闻', - docs: 'https://docs.rsshub.app/other.html#zhong-guo-you-zheng-su-di-wu-liu', - source: '/aboutus/xin_wen_yu_shi_jian.html', - target: '/ems/news', - }, - ], - }, 'popiapp.cn': { _name: 'Popi 提问箱', www: [ diff --git a/lib/router.js b/lib/router.js index 7aadd2b51..7e4211f74 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3011,9 +3011,6 @@ router.get('/open163/latest', lazyloadRouteHandler('./routes/netease/open/latest // Boston.com router.get('/boston/:tag?', lazyloadRouteHandler('./routes/boston/index')); -// 中国邮政速递物流 -router.get('/ems/news', lazyloadRouteHandler('./routes/ems/news')); - // 场库 router.get('/changku', lazyloadRouteHandler('./routes/changku/index')); router.get('/changku/cate/:postid', lazyloadRouteHandler('./routes/changku/index')); diff --git a/lib/v2/ems/apple.js b/lib/v2/ems/apple.js new file mode 100644 index 000000000..2eec3ef25 --- /dev/null +++ b/lib/v2/ems/apple.js @@ -0,0 +1,42 @@ +const got = require('@/utils/got'); +const { art } = require('@/utils/render'); +const path = require('path'); + +const rootUrl = 'https://www.ems.com.cn'; + +module.exports = async (ctx) => { + const id = ctx.params.id; + const link = `${rootUrl}/apple/query/${id}`; + const APIUrl = `${rootUrl}/apple/getMailNoLastRoutes`; + + const { trails } = await got + .post(APIUrl, { + form: { + mailNum: id, + }, + }) + .json(); + + let item; + try { + item = [ + { + title: `${trails[0][0].despatchCity} → ${trails[0][0].destinationCity}`, + link, + description: art(path.join(__dirname, 'templates/apple.art'), { + trails: trails[0], + }), + guid: trails[0][0], + }, + ]; + } catch (e) { + throw new Error(`没有找到 ${id} 的信息,请检查是否输入正确或者稍后再试。`); + } + + ctx.state.data = { + allowEmpty: true, + title: `Apple EMS 快递 ${id}`, + link, + item, + }; +}; diff --git a/lib/v2/ems/maintainer.js b/lib/v2/ems/maintainer.js new file mode 100644 index 000000000..2070e9f59 --- /dev/null +++ b/lib/v2/ems/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/news': ['luyuhuang'], + '/apple/:id': ['Fatpandac'], +}; diff --git a/lib/routes/ems/news.js b/lib/v2/ems/news.js similarity index 100% rename from lib/routes/ems/news.js rename to lib/v2/ems/news.js diff --git a/lib/v2/ems/radar.js b/lib/v2/ems/radar.js new file mode 100644 index 000000000..e42ccf1dc --- /dev/null +++ b/lib/v2/ems/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'ems.com.cn': { + _name: '中国邮政速递物流', + www: [ + { + title: '新闻', + docs: 'https://docs.rsshub.app/other.html#zhong-guo-you-zheng-su-di-wu-liu', + source: '/aboutus/xin_wen_yu_shi_jian.html', + target: '/ems/news', + }, + { + title: '苹果邮件', + docs: 'https://docs.rsshub.app/other.html#zhong-guo-you-zheng-su-di-wu-liu', + source: ['/apple/query/:id'], + target: '/apple/ems/:id', + }, + ], + }, +}; diff --git a/lib/v2/ems/router.js b/lib/v2/ems/router.js new file mode 100644 index 000000000..21fd46f7a --- /dev/null +++ b/lib/v2/ems/router.js @@ -0,0 +1,4 @@ +module.exports = function (router) { + router.get('/news', require('./news')); + router.get('/apple/:id', require('./apple')); +}; diff --git a/lib/v2/ems/templates/apple.art b/lib/v2/ems/templates/apple.art new file mode 100644 index 000000000..2659fe22c --- /dev/null +++ b/lib/v2/ems/templates/apple.art @@ -0,0 +1,6 @@ +{{ each trails}} +

{{ $value.optime }}

+

{{ $value.opreateType}}

+

{{ $value.processingInstructions }}

+
+{{/each}}