From c626f8ccde9944284812f0e8100f078cb838bd86 Mon Sep 17 00:00:00 2001 From: Nano Date: Mon, 8 Jan 2024 13:48:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(route):=20=E5=A4=84=E7=90=86=E5=A4=A7?= =?UTF-8?q?=E9=BA=A6=E7=BD=91=E6=9F=A5=E8=AF=A2=E7=BB=93=E6=9E=9C=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E7=9A=84=E6=83=85=E5=86=B5=20(#14203)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(route): 处理大麦网查询结果为空的情况 * refactor: migrate to v2 --------- --- lib/router.js | 2 +- lib/routes/damai/activity.js | 28 ------------------ lib/v2/damai/activity.js | 44 +++++++++++++++++++++++++++++ lib/v2/damai/maintainer.js | 3 ++ lib/v2/damai/radar.js | 13 +++++++++ lib/v2/damai/router.js | 3 ++ lib/v2/damai/templates/activity.art | 5 ++++ website/docs/routes/shopping.mdx | 2 +- 8 files changed, 70 insertions(+), 30 deletions(-) delete mode 100644 lib/routes/damai/activity.js create mode 100644 lib/v2/damai/activity.js create mode 100644 lib/v2/damai/maintainer.js create mode 100644 lib/v2/damai/radar.js create mode 100644 lib/v2/damai/router.js create mode 100644 lib/v2/damai/templates/activity.art diff --git a/lib/router.js b/lib/router.js index 9ba588b478503c..a5a00f7c91cd16 100644 --- a/lib/router.js +++ b/lib/router.js @@ -911,7 +911,7 @@ router.get('/4gamers/tag/:tag', lazyloadRouteHandler('./routes/4gamers/tag')); router.get('/4gamers/topic/:topic', lazyloadRouteHandler('./routes/4gamers/topic')); // 大麦网 -router.get('/damai/activity/:city/:category/:subcategory/:keyword?', lazyloadRouteHandler('./routes/damai/activity')); +// router.get('/damai/activity/:city/:category/:subcategory/:keyword?', lazyloadRouteHandler('./routes/damai/activity')); // 桂林电子科技大学新闻资讯 router.get('/guet/xwzx/:type?', lazyloadRouteHandler('./routes/guet/news')); diff --git a/lib/routes/damai/activity.js b/lib/routes/damai/activity.js deleted file mode 100644 index f20245c46fcd87..00000000000000 --- a/lib/routes/damai/activity.js +++ /dev/null @@ -1,28 +0,0 @@ -const got = require('@/utils/got'); - -module.exports = async (ctx) => { - const city = ctx.params.city === '全部' ? '' : ctx.params.city; - const category = ctx.params.category === '全部' ? '' : ctx.params.category; - const subcategory = ctx.params.subcategory === '全部' ? '' : ctx.params.subcategory; - const keyword = ctx.params.keyword ? ctx.params.keyword : ''; - - const url = `https://search.damai.cn/searchajax.html?keyword=${encodeURIComponent(keyword)}&cty=${encodeURIComponent(city)}&ctl=${encodeURIComponent(category)}&sctl=${encodeURIComponent( - subcategory - )}&tsg=0&st=&et=&order=3&pageSize=30&currPage=1&tn=`; - - const response = await got.get(url); - const data = response.data; - const list = data.pageData.resultData; - - ctx.state.data = { - title: `大麦网票务 - ${city ? city : '全国'} - ${category ? category : '全部分类'}${subcategory ? ' - ' + subcategory : ''}${keyword ? ' - ' + keyword : ''}`, - link: 'https://search.damai.cn/search.htm', - item: list.map((item) => ({ - title: item.nameNoHtml, - author: item.actors ? item.actors.replace(/<[^<>]*>/, '') : '大麦网', - description: `

${item.description}

地点:${item.venuecity} | ${item.venue}

时间:${item.showtime}

票价:${item.price_str}

`, - pubDate: new Date(), - link: `https://detail.damai.cn/item.htm?id=${item.projectid}`, - })), - }; -}; diff --git a/lib/v2/damai/activity.js b/lib/v2/damai/activity.js new file mode 100644 index 00000000000000..bc6bb8ea91c9f5 --- /dev/null +++ b/lib/v2/damai/activity.js @@ -0,0 +1,44 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { art } = require('@/utils/render'); +const { join } = require('path'); + +module.exports = async (ctx) => { + const city = ctx.params.city === '全部' ? '' : ctx.params.city; + const category = ctx.params.category === '全部' ? '' : ctx.params.category; + const subcategory = ctx.params.subcategory === '全部' ? '' : ctx.params.subcategory; + const keyword = ctx.params.keyword ? ctx.params.keyword : ''; + + const url = 'https://search.damai.cn/searchajax.html'; + + const response = await got(url, { + searchParams: { + keyword, + cty: city, + ctl: category, + sctl: subcategory, + tsg: 0, + st: '', + et: '', + order: 3, + pageSize: 30, + currPage: 1, + tn: '', + }, + }); + const data = response.data; + const list = data.pageData.resultData || []; + + ctx.state.data = { + title: `大麦网票务 - ${city || '全国'} - ${category || '全部分类'}${subcategory ? ' - ' + subcategory : ''}${keyword ? ' - ' + keyword : ''}`, + link: 'https://search.damai.cn/search.htm', + item: list.map((item) => ({ + title: item.nameNoHtml, + author: item.actors ? cheerio.load(item.actors, null, false).text() : '大麦网', + description: art(join(__dirname, 'templates/activity.art'), { + item, + }), + link: `https://detail.damai.cn/item.htm?id=${item.projectid}`, + })), + }; +}; diff --git a/lib/v2/damai/maintainer.js b/lib/v2/damai/maintainer.js new file mode 100644 index 00000000000000..1e5144889ef33a --- /dev/null +++ b/lib/v2/damai/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/activity/:city/:category/:subcategory/:keyword?': ['hoilc'], +}; diff --git a/lib/v2/damai/radar.js b/lib/v2/damai/radar.js new file mode 100644 index 00000000000000..bd47baad76848c --- /dev/null +++ b/lib/v2/damai/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'damai.cn': { + _name: '大麦网', + search: [ + { + title: '票务更新', + docs: 'https://docs.rsshub.app/routes/shopping#da-mai-wang', + source: ['/search.html'], + target: (_params, url) => `/damai/activity/全部/全部/全部/${new URL(url).searchParams.get('keyword') || ''}`, + }, + ], + }, +}; diff --git a/lib/v2/damai/router.js b/lib/v2/damai/router.js new file mode 100644 index 00000000000000..98e08502ea7df9 --- /dev/null +++ b/lib/v2/damai/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/activity/:city/:category/:subcategory/:keyword?', require('./activity')); +}; diff --git a/lib/v2/damai/templates/activity.art b/lib/v2/damai/templates/activity.art new file mode 100644 index 00000000000000..5e0e359c541af8 --- /dev/null +++ b/lib/v2/damai/templates/activity.art @@ -0,0 +1,5 @@ + +

{{@ item.description }}

+

地点:{{ item.venuecity }} | {{ item.venue }}

+

时间:{{ item.showtime }}

+

票价:{{ item.price_str }}

diff --git a/website/docs/routes/shopping.mdx b/website/docs/routes/shopping.mdx index 749e0a03579794..767cdd6bcee773 100644 --- a/website/docs/routes/shopping.mdx +++ b/website/docs/routes/shopping.mdx @@ -239,7 +239,7 @@ For instance, in `https://www.zagg.com/en_us/new-arrivals?brand=164&cat=3038%2C3 ### 票务更新 {#da-mai-wang-piao-wu-geng-xin} - + 城市、分类名、子分类名,请参见[大麦网搜索页面](https://search.damai.cn/search.htm)