Skip to content

Commit

Permalink
fix(route): 处理大麦网查询结果为空的情况 (#14203)
Browse files Browse the repository at this point in the history
* fix(route): 处理大麦网查询结果为空的情况

* refactor: migrate to v2

---------
  • Loading branch information
Konano authored Jan 8, 2024
1 parent acf59ee commit c626f8c
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
28 changes: 0 additions & 28 deletions lib/routes/damai/activity.js

This file was deleted.

44 changes: 44 additions & 0 deletions lib/v2/damai/activity.js
Original file line number Diff line number Diff line change
@@ -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}`,
})),
};
};
3 changes: 3 additions & 0 deletions lib/v2/damai/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/activity/:city/:category/:subcategory/:keyword?': ['hoilc'],
};
13 changes: 13 additions & 0 deletions lib/v2/damai/radar.js
Original file line number Diff line number Diff line change
@@ -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') || ''}`,
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/damai/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/activity/:city/:category/:subcategory/:keyword?', require('./activity'));
};
5 changes: 5 additions & 0 deletions lib/v2/damai/templates/activity.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<img src="{{ item.verticalPic }}">
<p>{{@ item.description }}</p>
<p>地点:{{ item.venuecity }} | {{ item.venue }}</p>
<p>时间:{{ item.showtime }}</p>
<p>票价:{{ item.price_str }}</p>
2 changes: 1 addition & 1 deletion website/docs/routes/shopping.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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}

<Route author="hoilc" example="/damai/activity/上海/音乐会/全部/柴可夫斯基" path="/damai/activity/:city/:category/:subcategory/:keyword?" paramsDesc={['城市, 如果不需要限制, 请填入`全部`', '分类, 如果不需要限制, 请填入`全部`', '子分类, 如果不需要限制, 请填入`全部`', '搜索关键字, 置空为不限制']} />
<Route author="hoilc" example="/damai/activity/上海/音乐会/全部/柴可夫斯基" path="/damai/activity/:city/:category/:subcategory/:keyword?" paramsDesc={['城市如果不需要限制请填入`全部`', '分类如果不需要限制请填入`全部`', '子分类如果不需要限制请填入`全部`', '搜索关键字置空为不限制']} radar="1" />

城市、分类名、子分类名,请参见[大麦网搜索页面](https://search.damai.cn/search.htm)

Expand Down

0 comments on commit c626f8c

Please sign in to comment.