Files
RSSHub/lib/v2/showstart/service.js
T
lchtao26 bb589044a0 feat(route/秀动网): add '/params' route for route params look up, add more detail into '/event' feed item description (#13879)
* change '/search/:keyword' to optional

* feat: add more info to description

* feat: add '/params/city' and '/params/style' for params look up

reason for adding this route:

it's hard to find route params in url, expecially in mobile mode, the
wap.showstasrt.com website url doesn't match the shows city and style

* chore: implement sortBy and uniqBy

* chore: move sortBy, uniqBy to utils
2023-11-25 01:05:35 +08:00

91 lines
2.8 KiB
JavaScript

const { HOST } = require('./const');
const { getAccessToken, post, sortBy, uniqBy } = require('./utils');
async function fetchActivityList(
params = {
pageNo: '1',
pageSize: '30',
cityCode: '',
activityIds: '',
coupon: '',
keyword: '',
organizerId: '',
performerId: '',
showStyle: '',
showTime: '',
showType: '',
siteId: '',
sortType: '',
themeId: '',
timeRange: '',
tourId: '',
type: '',
tag: '',
}
) {
const accessToken = await getAccessToken();
const resp = await post('/web/activity/list', accessToken, params);
const image = (src) => (src ? `<img src="${src}" />` : '');
const time = (time) => (time ? `<p>演出时间:${time}</p>` : '');
const address = (cityName, siteName) => (cityName || siteName ? `<p>地址:${[cityName, siteName].join(' - ')}</p>` : '');
const performers = (name) => (name ? `<p>艺人:${name}</p>` : '');
const price = (price) => (price ? `<p>票价:${price}</p>` : '');
return {
items: resp.result.result.map((item) => ({
title: item.title,
link: `${HOST}/event/${item.id}`,
description: [image(item.poster), time(item.showTime), address(item.cityName, item.siteName), performers(item.performers), price(item.price)].join(''),
})),
};
}
async function fetchParams() {
const accessToken = await getAccessToken();
return post('/web/activity/list/params', accessToken);
}
async function fetchCityList() {
const resp = await fetchParams();
const cities = sortBy(resp.result, 'cityCode');
return cities.map((item) => ({
title: item.cityName,
link: `${HOST}/event/list?cityCode=${item.cityCode}`,
description: `cityCode: ${item.cityCode}`,
}));
}
// styles is embed in each city item
// so we need to fetch all city items and then extract styles from them
async function fetchStyleList() {
const resp = await fetchParams();
let styles = resp.result.flatMap((item) => item.styles);
styles = uniqBy(styles, 'key');
styles = sortBy(styles, 'key');
return styles.map((item) => ({
title: item.showName,
link: `${HOST}/event/list?showStyle=${item.key}`,
description: `showStyle: ${item.key}`,
}));
}
async function fetchDictionary(cityCode, showStyle) {
const resp = await fetchParams();
const target = resp.result.find((item) => item.cityCode === cityCode);
if (!target) {
return {};
}
return {
cityName: target.cityName,
showName: target.styles.find((item) => item.key === showStyle)?.showName,
};
}
module.exports = {
fetchActivityList,
fetchCityList,
fetchStyleList,
fetchDictionary,
};