From 6bf09c868d7ecaa004706d819a55f90767c95f4d Mon Sep 17 00:00:00 2001 From: Fatpandac <1779196284@qq.com> Date: Wed, 2 Feb 2022 23:53:29 +0800 Subject: [PATCH] fix(route): fix taobao/zhongchou route is empty and refactor to V2 standard (#8958) --- docs/shopping.md | 2 +- lib/router.js | 3 - lib/v2/taobao/maintainer.js | 3 + lib/v2/taobao/radar.js | 117 +++++++++++++++++++++++++ lib/v2/taobao/router.js | 3 + lib/v2/taobao/templates/zhongchou.art | 4 + lib/{routes => v2}/taobao/zhongchou.js | 13 ++- 7 files changed, 134 insertions(+), 11 deletions(-) create mode 100644 lib/v2/taobao/maintainer.js create mode 100644 lib/v2/taobao/radar.js create mode 100644 lib/v2/taobao/router.js create mode 100644 lib/v2/taobao/templates/zhongchou.art rename lib/{routes => v2}/taobao/zhongchou.js (73%) diff --git a/docs/shopping.md b/docs/shopping.md index b391b4317..d2a2ddec1 100644 --- a/docs/shopping.md +++ b/docs/shopping.md @@ -312,7 +312,7 @@ For instance, in + | 全部 | 科技 | 食品 | 动漫 | 设计 | 公益 | 娱乐 | 影音 | 书籍 | 游戏 | 其他 | | ---- | ---- | ----------- | ---- | ------ | ---- | ---- | ----- | ---- | ---- | ----- | diff --git a/lib/router.js b/lib/router.js index 44031adb8..53f3d821d 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1247,9 +1247,6 @@ router.get('/patchwork.kernel.org/comments/:id', lazyloadRouteHandler('./routes/ // 京东众筹 router.get('/jingdong/zhongchou/:type/:status/:sort', lazyloadRouteHandler('./routes/jingdong/zhongchou')); -// 淘宝众筹 -router.get('/taobao/zhongchou/:type?', lazyloadRouteHandler('./routes/taobao/zhongchou')); - // All Poetry router.get('/allpoetry/:order?', lazyloadRouteHandler('./routes/allpoetry/order')); diff --git a/lib/v2/taobao/maintainer.js b/lib/v2/taobao/maintainer.js new file mode 100644 index 000000000..9c3e1c241 --- /dev/null +++ b/lib/v2/taobao/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/zhongchou/:type?': ['xyqfer', 'Fatpandac'], +}; diff --git a/lib/v2/taobao/radar.js b/lib/v2/taobao/radar.js new file mode 100644 index 000000000..34e787b96 --- /dev/null +++ b/lib/v2/taobao/radar.js @@ -0,0 +1,117 @@ +module.exports = { + 'taobao.com': { + _name: '淘宝', + izhongchou: [ + { + title: '淘宝众筹全部', + docs: 'https://docs.rsshub.app/shopping.html#tao-bao-zhong-chou-zhong-chou-xiang-mu', + source: ['/list.htm'], + target: (params, url) => { + if (new URLSearchParams(new URL(url).search).get('type') === '') { + return '/taobao/zhongchou/all'; + } + }, + }, + { + title: '淘宝众筹科技', + docs: 'https://docs.rsshub.app/shopping.html#tao-bao-zhong-chou-zhong-chou-xiang-mu', + source: ['/list.htm'], + target: (params, url) => { + if (new URLSearchParams(new URL(url).search).get('type') === '121288001') { + return '/taobao/zhongchou/tech'; + } + }, + }, + { + title: '淘宝众筹食品', + docs: 'https://docs.rsshub.app/shopping.html#tao-bao-zhong-chou-zhong-chou-xiang-mu', + source: ['/list.htm'], + target: (params, url) => { + if (new URLSearchParams(new URL(url).search).get('type') === '123330001,125672021') { + return '/taobao/zhongchou/agriculture'; + } + }, + }, + { + title: '淘宝众筹动漫', + docs: 'https://docs.rsshub.app/shopping.html#tao-bao-zhong-chou-zhong-chou-xiang-mu', + source: ['/list.htm'], + target: (params, url) => { + if (new URLSearchParams(new URL(url).search).get('type') === '122018001') { + return '/taobao/zhongchou/acg'; + } + }, + }, + { + title: '淘宝众筹设计', + docs: 'https://docs.rsshub.app/shopping.html#tao-bao-zhong-chou-zhong-chou-xiang-mu', + source: ['/list.htm'], + target: (params, url) => { + if (new URLSearchParams(new URL(url).search).get('type') === '121292001,126176002,126202001') { + return '/taobao/zhongchou/design'; + } + }, + }, + { + title: '淘宝众筹公益', + docs: 'https://docs.rsshub.app/shopping.html#tao-bao-zhong-chou-zhong-chou-xiang-mu', + source: ['/list.htm'], + target: (params, url) => { + if (new URLSearchParams(new URL(url).search).get('type') === '121280001') { + return '/taobao/zhongchou/love'; + } + }, + }, + { + title: '淘宝众筹娱乐', + docs: 'https://docs.rsshub.app/shopping.html#tao-bao-zhong-chou-zhong-chou-xiang-mu', + source: ['/list.htm'], + target: (params, url) => { + if (new URLSearchParams(new URL(url).search).get('type') === '121284001') { + return '/taobao/zhongchou/tele'; + } + }, + }, + { + title: '淘宝众筹影音', + docs: 'https://docs.rsshub.app/shopping.html#tao-bao-zhong-chou-zhong-chou-xiang-mu', + source: ['/list.htm'], + target: (params, url) => { + if (new URLSearchParams(new URL(url).search).get('type') === '121278001') { + return '/taobao/zhongchou/music'; + } + }, + }, + { + title: '淘宝众筹书籍', + docs: 'https://docs.rsshub.app/shopping.html#tao-bao-zhong-chou-zhong-chou-xiang-mu', + source: ['/list.htm'], + target: (params, url) => { + if (new URLSearchParams(new URL(url).search).get('type') === '121274002') { + return '/taobao/zhongchou/book'; + } + }, + }, + { + title: '淘宝众筹游戏', + docs: 'https://docs.rsshub.app/shopping.html#tao-bao-zhong-chou-zhong-chou-xiang-mu', + source: ['/list.htm'], + target: (params, url) => { + if (new URLSearchParams(new URL(url).search).get('type') === '122020001') { + return '/taobao/zhongchou/game'; + } + }, + }, + { + title: '淘宝众筹其他', + docs: 'https://docs.rsshub.app/shopping.html#tao-bao-zhong-chou-zhong-chou-xiang-mu', + source: ['/list.htm'], + target: (params, url) => { + if (new URLSearchParams(new URL(url).search).get('type') === '125706031,125888001,125886001,123332001') { + return '/taobao/zhongchou/other'; + } + }, + }, + ], + }, +}; diff --git a/lib/v2/taobao/router.js b/lib/v2/taobao/router.js new file mode 100644 index 000000000..3baa588ae --- /dev/null +++ b/lib/v2/taobao/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/zhongchou/:type?', require('./zhongchou')); +}; diff --git a/lib/v2/taobao/templates/zhongchou.art b/lib/v2/taobao/templates/zhongchou.art new file mode 100644 index 000000000..3338a619e --- /dev/null +++ b/lib/v2/taobao/templates/zhongchou.art @@ -0,0 +1,4 @@ +

+达成率: {{item.finish_per}}%
+已筹金额: {{item.curr_money}}元
+支持人数: {{item.buy_amount}}
diff --git a/lib/routes/taobao/zhongchou.js b/lib/v2/taobao/zhongchou.js similarity index 73% rename from lib/routes/taobao/zhongchou.js rename to lib/v2/taobao/zhongchou.js index fd4ea2c4e..857cec8de 100644 --- a/lib/routes/taobao/zhongchou.js +++ b/lib/v2/taobao/zhongchou.js @@ -1,4 +1,6 @@ const got = require('@/utils/got'); +const { art } = require('@/utils/render'); +const path = require('path'); module.exports = async (ctx) => { const { type = 'all' } = ctx.params; @@ -15,7 +17,7 @@ module.exports = async (ctx) => { game: '122020001', other: '125706031,125888001,125886001,123332001', }; - const url = `https://izhongchou.taobao.com/dream/ajax/getProjectList.htm?page=1&pageSize=20&projectType=${encodeURIComponent(map[type])}&type=6&status=&sort=1&_ksTS=${Date.now()}_104&callback=`; + const url = `https://izhongchou.taobao.com/dream/ajax/getProjectListNew.htm?_input_charset=utf-8&type=6&pageSize=20&page=1&sort=1&status=&projectType=${encodeURIComponent(map[type])}&_=${Date.now()}&callback=`; const response = await got({ method: 'get', url, @@ -24,12 +26,9 @@ module.exports = async (ctx) => { const items = response.data.data.map((item) => { const title = item.name; const link = `https://izhongchou.taobao.com/dreamdetail.htm?id=${item.id}`; - const description = ` -

- 达成率: ${item.finish_per}%
- 已筹金额: ${item.curr_money}元
- 支持人数: ${item.buy_amount}
- `; + const description = art(path.join(__dirname, 'templates/zhongchou.art'), { + item, + }); return { title,