From f477e3e8bfce2025af2a3c881ca45ce6a0356c85 Mon Sep 17 00:00:00 2001 From: b0ttle <48851366+b0ttle@users.noreply.github.com> Date: Thu, 19 May 2022 01:29:58 +0800 Subject: [PATCH] fix(route): fixed routes/earthquake and ceic timezone shift (#9780) * fixed routes/earthquake and ceic timezone shift * use utils/timezone and remove changes on yarn.lock * edit format problem * refactor: migrate to v2 --- docs/forecast.md | 12 +++++++++++- lib/router.js | 7 +++---- lib/{routes => v2}/earthquake/ceic.js | 4 +++- lib/{routes => v2}/earthquake/index.js | 8 +++++--- lib/v2/earthquake/maintainer.js | 4 ++++ lib/v2/earthquake/radar.js | 24 ++++++++++++++++++++++++ lib/v2/earthquake/router.js | 4 ++++ 7 files changed, 54 insertions(+), 9 deletions(-) rename lib/{routes => v2}/earthquake/ceic.js (91%) rename lib/{routes => v2}/earthquake/index.js (83%) create mode 100644 lib/v2/earthquake/maintainer.js create mode 100644 lib/v2/earthquake/radar.js create mode 100644 lib/v2/earthquake/router.js diff --git a/docs/forecast.md b/docs/forecast.md index 73b15b6da..cad3117d2 100644 --- a/docs/forecast.md +++ b/docs/forecast.md @@ -26,7 +26,17 @@ pageClass: routes ### 中国地震台 - + + +| 参数 | 类型 | +| -- | ---------------- | +| 1 | 最近 24 小时地震信息 | +| 2 | 最近 48 小时地震信息 | +| 5 | 最近一年 3.0 级以上地震信息 | +| 7 | 最近一年 3.0 级以下地震 | +| 8 | 最近一年 4.0 级以上地震信息 | +| 9 | 最近一年 5.0 级以上地震信息 | +| 0 | 最近一年 6.0 级以上地震信息 | 可通过全局过滤参数订阅您感兴趣的地区. diff --git a/lib/router.js b/lib/router.js index 627718aab..3b3703c2e 100644 --- a/lib/router.js +++ b/lib/router.js @@ -453,11 +453,10 @@ router.get('/hopper/:lowestOnly/:from/:to?', lazyloadRouteHandler('./routes/hopp router.get('/mafengwo/note/:type', lazyloadRouteHandler('./routes/mafengwo/note')); router.get('/mafengwo/ziyouxing/:code', lazyloadRouteHandler('./routes/mafengwo/ziyouxing')); -// 中国地震局震情速递(与地震台网同步更新) -router.get('/earthquake/:region?', lazyloadRouteHandler('./routes/earthquake')); - +// 中国地震局震情速递(与地震台网同步更新)migrated to v2 +// router.get('/earthquake/:region?', lazyloadRouteHandler('./routes/earthquake')); // 中国地震台网 -router.get('/earthquake/ceic/:type', lazyloadRouteHandler('./routes/earthquake/ceic')); +// router.get('/earthquake/ceic/:type', lazyloadRouteHandler('./routes/earthquake/ceic')); // 小说 router.get('/novel/biquge/:id', lazyloadRouteHandler('./routes/novel/biquge')); diff --git a/lib/routes/earthquake/ceic.js b/lib/v2/earthquake/ceic.js similarity index 91% rename from lib/routes/earthquake/ceic.js rename to lib/v2/earthquake/ceic.js index 1181c46d2..2fc25177d 100644 --- a/lib/routes/earthquake/ceic.js +++ b/lib/v2/earthquake/ceic.js @@ -1,4 +1,6 @@ const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); module.exports = async (ctx) => { let type = Number(ctx.params.type); @@ -57,7 +59,7 @@ module.exports = async (ctx) => { return { title: `${entity.LOCATION_C}发生${entity.M}级地震`, link: `${baseUrl}/${NEW_DID}.html`, - pubDate: new Date(entity.O_TIME).toUTCString(), + pubDate: timezone(parseDate(entity.O_TIME, 'YYYY-MM-DD HH:mm:ss'), +8), description: contentBuilder.join('
'), guid: NEW_DID, }; diff --git a/lib/routes/earthquake/index.js b/lib/v2/earthquake/index.js similarity index 83% rename from lib/routes/earthquake/index.js rename to lib/v2/earthquake/index.js index 974d48af8..da27abe04 100644 --- a/lib/routes/earthquake/index.js +++ b/lib/v2/earthquake/index.js @@ -1,7 +1,9 @@ const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); module.exports = async (ctx) => { - const region = ctx.params.region || 1; + const region = ctx.params.region ?? 1; const api = 'https://www.cea.gov.cn/eportal/ui?struts.portlet.mode=view&struts.portlet.action=/portlet/expressEarthquake!queryExpressEarthquakeList.action&pageId=363409&moduleId=a852ba487b534470a84a30f00e7d6670'; const link = 'https://www.cea.gov.cn/cea/xwzx/zqsd/index.html'; const response = await got({ @@ -18,14 +20,14 @@ module.exports = async (ctx) => { const out = data.map((item) => { const { id, epicenter, latitudes, longitudes, depth } = item; - const date = item.orig_time.slice(0, -2); + const date = item.orig_time; const num = item.num_mag; const description = `北京时间${date},${epicenter}(纬度${latitudes}度,经度${longitudes}度)发生${num}级地震,震源深度${depth}千米`; return { title: `${epicenter}发生${num}级地震`, link: `https://www.cea.gov.cn/eportal/ui?struts.portlet.mode=view&struts.portlet.action=/portlet/expressEarthquake!toNewInfoView.action&pageId=366521&id=${id}`, - pubDate: new Date(date).toUTCString(), + pubDate: timezone(parseDate(date, 'YYYY-MM-DD HH:mm:ss'), +8), description, }; }); diff --git a/lib/v2/earthquake/maintainer.js b/lib/v2/earthquake/maintainer.js new file mode 100644 index 000000000..291da67fd --- /dev/null +++ b/lib/v2/earthquake/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/ceic/:type?': ['SettingDust'], + '/:region?': ['LogicJake'], +}; diff --git a/lib/v2/earthquake/radar.js b/lib/v2/earthquake/radar.js new file mode 100644 index 000000000..08e0fa38b --- /dev/null +++ b/lib/v2/earthquake/radar.js @@ -0,0 +1,24 @@ +module.exports = { + 'ac.cn': { + _name: '地震速报', + 'www.ceic': [ + { + title: '中国地震台', + docs: 'https://docs-rsshub.pages.dev/forecast.html#di-zhen-su-bao', + source: ['/speedsearch', '/'], + target: '/earthquake/ceic', + }, + ], + }, + 'cea.gov.cn': { + _name: '地震速报', + www: [ + { + title: '中国地震局', + docs: 'https://docs-rsshub.pages.dev/forecast.html#di-zhen-su-bao', + source: ['/cea/xwzx/zqsd/index.html', '/'], + target: '/earthquake', + }, + ], + }, +}; diff --git a/lib/v2/earthquake/router.js b/lib/v2/earthquake/router.js new file mode 100644 index 000000000..d10ad2bf9 --- /dev/null +++ b/lib/v2/earthquake/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/ceic/:type?', require('./ceic')); + router.get('/:region?', require('./index')); +};