feat(route/showstart): add route for site; add typescript types for other routes; replace got with ofetch (#16351)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Route } from '@/types';
|
||||
import { Data, Route } from '@/types';
|
||||
import { TITLE, HOST } from './const';
|
||||
import { fetchPerformerInfo } from './service';
|
||||
import type { Context } from 'hono';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/artist/:id',
|
||||
@@ -20,15 +21,15 @@ export const route: Route = {
|
||||
source: ['www.showstart.com/artist/:id'],
|
||||
},
|
||||
],
|
||||
name: '音乐人 - 演出更新',
|
||||
name: '按音乐人 - 演出更新',
|
||||
maintainers: ['lchtao26'],
|
||||
handler,
|
||||
description: `:::tip
|
||||
音乐人 ID 查询: \`/showstart/search/artist/:keyword\`,如: [https://rsshub.app/showstart/search/artist/ 周杰伦](https://rsshub.app/showstart/search/artist/周杰伦)
|
||||
音乐人 ID 查询: \`/showstart/search/artist/:keyword\`,如: [https://rsshub.app/showstart/search/artist/周杰伦](https://rsshub.app/showstart/search/artist/周杰伦)
|
||||
:::`,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
async function handler(ctx: Context): Promise<Data> {
|
||||
const id = ctx.req.param('id');
|
||||
const artist = await fetchPerformerInfo({
|
||||
performerId: id,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Route } from '@/types';
|
||||
import { Data, Route } from '@/types';
|
||||
import { TITLE, HOST } from './const';
|
||||
import { fetchBrandInfo } from './service';
|
||||
import type { Context } from 'hono';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/brand/:id',
|
||||
@@ -20,15 +21,15 @@ export const route: Route = {
|
||||
source: ['www.showstart.com/host/:id'],
|
||||
},
|
||||
],
|
||||
name: '厂牌 - 演出更新',
|
||||
name: '按厂牌 - 演出更新',
|
||||
maintainers: ['lchtao26'],
|
||||
handler,
|
||||
description: `:::tip
|
||||
厂牌 ID 查询: \`/showstart/search/brand/:keyword\`,如: [https://rsshub.app/showstart/search/brand/ 声场](https://rsshub.app/showstart/search/brand/声场)
|
||||
厂牌 ID 查询: \`/showstart/search/brand/:keyword\`,如: [https://rsshub.app/showstart/search/brand/声场](https://rsshub.app/showstart/search/brand/声场)
|
||||
:::`,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
async function handler(ctx: Context): Promise<Data> {
|
||||
const id = ctx.req.param('id');
|
||||
const brand = await fetchBrandInfo({
|
||||
brandId: id,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Route } from '@/types';
|
||||
import { Data, Route } from '@/types';
|
||||
import { TITLE, HOST } from './const';
|
||||
import { fetchActivityList, fetchDictionary } from './service';
|
||||
import type { Context } from 'hono';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/event/:cityCode/:showStyle?',
|
||||
@@ -15,19 +16,19 @@ export const route: Route = {
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
name: '演出更新',
|
||||
name: '按城市 - 演出更新',
|
||||
maintainers: ['lchtao26'],
|
||||
handler,
|
||||
description: `:::tip
|
||||
- 演出城市 \`cityCode\` 查询: \`/showstart/search/city/:keyword\`, 如: [https://rsshub.app/showstart/search/city/ 杭州](https://rsshub.app/showstart/search/city/杭州)
|
||||
- 演出城市 \`cityCode\` 查询: \`/showstart/search/city/:keyword\`, 如: [https://rsshub.app/showstart/search/city/杭州](https://rsshub.app/showstart/search/city/杭州)
|
||||
|
||||
- 演出风格 \`showStyle\` 查询: \`/showstart/search/style/:keyword\`,如: [https://rsshub.app/showstart/search/style/ 摇滚](https://rsshub.app/showstart/search/style/摇滚)
|
||||
- 演出风格 \`showStyle\` 查询: \`/showstart/search/style/:keyword\`,如: [https://rsshub.app/showstart/search/style/摇滚](https://rsshub.app/showstart/search/style/摇滚)
|
||||
:::`,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const cityCode = Number.parseInt(ctx.req.param('cityCode'));
|
||||
const showStyle = Number.parseInt(ctx.req.param('showStyle'));
|
||||
async function handler(ctx: Context): Promise<Data> {
|
||||
const cityCode = Number.parseInt(ctx.req.param('cityCode')).toString();
|
||||
const showStyle = Number.parseInt(ctx.req.param('showStyle')).toString();
|
||||
const items = await fetchActivityList({
|
||||
cityCode,
|
||||
showStyle,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Route } from '@/types';
|
||||
import { Data, Route } from '@/types';
|
||||
import { TITLE, HOST } from './const';
|
||||
import { fetchActivityList, fetchPerformerList, fetchBrandList, fetchCityList, fetchStyleList } from './service';
|
||||
import { fetchActivityList, fetchPerformerList, fetchSiteList, fetchBrandList, fetchCityList, fetchStyleList } from './service';
|
||||
import type { Context } from 'hono';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/search/:type/:keyword?',
|
||||
@@ -20,7 +21,7 @@ export const route: Route = {
|
||||
handler,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
async function handler(ctx: Context): Promise<Data> {
|
||||
const type = ctx.req.param('type') || '';
|
||||
const keyword = ctx.req.param('keyword') || '';
|
||||
|
||||
@@ -31,35 +32,36 @@ async function handler(ctx) {
|
||||
link: HOST,
|
||||
item: await fetchActivityList({ keyword }),
|
||||
};
|
||||
break;
|
||||
case 'artist':
|
||||
return {
|
||||
title: `${TITLE} - 搜艺人 - ${keyword || '全部'}`,
|
||||
link: HOST,
|
||||
item: await fetchPerformerList({ searchKeyword: keyword }),
|
||||
};
|
||||
break;
|
||||
case 'site':
|
||||
return {
|
||||
title: `${TITLE} - 搜场地 - ${keyword || '全部'}`,
|
||||
link: HOST,
|
||||
item: await fetchSiteList({ searchKeyword: keyword }),
|
||||
};
|
||||
case 'brand':
|
||||
return {
|
||||
title: `${TITLE} - 搜厂牌 - ${keyword || '全部'}`,
|
||||
link: HOST,
|
||||
item: await fetchBrandList({ searchKeyword: keyword }),
|
||||
};
|
||||
break;
|
||||
case 'city':
|
||||
return {
|
||||
title: `${TITLE} - 搜城市 - ${keyword || '全部'}`,
|
||||
link: HOST,
|
||||
item: await fetchCityList(keyword),
|
||||
};
|
||||
break;
|
||||
case 'style':
|
||||
return {
|
||||
title: `${TITLE} - 搜风格 - ${keyword || '全部'}`,
|
||||
link: HOST,
|
||||
item: await fetchStyleList(keyword),
|
||||
};
|
||||
break;
|
||||
default:
|
||||
return {
|
||||
title: `${TITLE} - 搜演出 - ${type || '全部'}`,
|
||||
|
||||
@@ -2,37 +2,39 @@ import { HOST } from './const';
|
||||
import { getAccessToken, post, sortBy, uniqBy } from './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: '',
|
||||
}
|
||||
params: Partial<{
|
||||
pageNo: string;
|
||||
pageSize: string;
|
||||
cityCode: string;
|
||||
activityIds: string;
|
||||
coupon: string;
|
||||
keyword: string;
|
||||
organizerId: string;
|
||||
performerId: string;
|
||||
showStyle: string;
|
||||
showTime: string;
|
||||
showType: string;
|
||||
siteId: string;
|
||||
sortType: string;
|
||||
themeId: string;
|
||||
timeRange: string;
|
||||
tourId: string;
|
||||
type: string;
|
||||
tag: string;
|
||||
}>
|
||||
) {
|
||||
params.pageNo = params.pageNo || '1';
|
||||
params.pageSize = params.pageSize || '30';
|
||||
const accessToken = await getAccessToken();
|
||||
const resp = await post('/web/activity/list', accessToken, params);
|
||||
return resp.result.result.map((item) => formatActivity(item));
|
||||
}
|
||||
|
||||
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>` : '');
|
||||
const image = (src: string) => (src ? `<img src="${src}" />` : '');
|
||||
const time = (time: string) => (time ? `<p>演出时间:${time}</p>` : '');
|
||||
const address = (cityName: string, siteName: string) => (cityName || siteName ? `<p>地址:${[cityName, siteName].join(' - ')}</p>` : '');
|
||||
const performers = (name: string) => (name ? `<p>艺人:${name}</p>` : '');
|
||||
const price = (price: string) => (price ? `<p>票价:${price}</p>` : '');
|
||||
|
||||
function formatActivity(item) {
|
||||
return {
|
||||
@@ -43,13 +45,15 @@ function formatActivity(item) {
|
||||
}
|
||||
|
||||
async function fetchPerformerList(
|
||||
params = {
|
||||
pageNo: '1',
|
||||
pageSize: '30',
|
||||
searchKeyword: '',
|
||||
styleId: '',
|
||||
}
|
||||
params: Partial<{
|
||||
pageNo: string;
|
||||
pageSize: string;
|
||||
searchKeyword: string;
|
||||
styleId: string;
|
||||
}>
|
||||
) {
|
||||
params.pageNo = params.pageNo || '1';
|
||||
params.pageSize = params.pageSize || '30';
|
||||
const accessToken = await getAccessToken();
|
||||
const resp = await post('/web/performer/list', accessToken, params);
|
||||
return resp.result.result.map((item) => ({
|
||||
@@ -59,15 +63,11 @@ async function fetchPerformerList(
|
||||
}));
|
||||
}
|
||||
|
||||
async function fetchPerformerInfo(
|
||||
params = {
|
||||
performerId: '',
|
||||
}
|
||||
) {
|
||||
async function fetchPerformerInfo(params: { performerId: string }) {
|
||||
const accessToken = await getAccessToken();
|
||||
const resp = await post('/web/performer/info', accessToken, params);
|
||||
return {
|
||||
id: params.id,
|
||||
id: params.performerId,
|
||||
name: resp.result.name,
|
||||
content: resp.result.content,
|
||||
avatar: resp.result.avatar,
|
||||
@@ -77,15 +77,11 @@ async function fetchPerformerInfo(
|
||||
};
|
||||
}
|
||||
|
||||
async function fetchBrandInfo(
|
||||
params = {
|
||||
brandId: '',
|
||||
}
|
||||
) {
|
||||
async function fetchBrandInfo(params: { brandId: string }) {
|
||||
const accessToken = await getAccessToken();
|
||||
const resp = await post('/web/brand/info', accessToken, params);
|
||||
return {
|
||||
id: params.id,
|
||||
id: params.brandId,
|
||||
name: resp.result.name,
|
||||
content: resp.result.content,
|
||||
avatar: resp.result.avatar,
|
||||
@@ -94,13 +90,45 @@ async function fetchBrandInfo(
|
||||
};
|
||||
}
|
||||
|
||||
async function fetchBrandList(
|
||||
params = {
|
||||
pageNo: '1',
|
||||
pageSize: '30',
|
||||
searchKeyword: '',
|
||||
}
|
||||
async function fetchSiteList(
|
||||
params: Partial<{
|
||||
pageNo: string;
|
||||
pageSize: string;
|
||||
searchKeyword: string;
|
||||
}>
|
||||
) {
|
||||
params.pageNo = params.pageNo || '1';
|
||||
params.pageSize = params.pageSize || '30';
|
||||
const accessToken = await getAccessToken();
|
||||
const resp = await post('/web/site/list', accessToken, params);
|
||||
return resp.result.result.map((item) => ({
|
||||
title: `${item.cityName} - ${item.name}`,
|
||||
link: `${HOST}/venue/${item.id}`,
|
||||
description: `id: ${item.id}`,
|
||||
}));
|
||||
}
|
||||
|
||||
async function fetchSiteInfo(params: { siteId: string }) {
|
||||
const accessToken = await getAccessToken();
|
||||
const resp = await post('/web/site/info', accessToken, params);
|
||||
return {
|
||||
id: params.siteId,
|
||||
name: `${resp.result.cityName} - ${resp.result.name}`,
|
||||
address: resp.result.address,
|
||||
avatar: resp.result.avatar,
|
||||
poster: resp.result.poster,
|
||||
};
|
||||
}
|
||||
|
||||
async function fetchBrandList(
|
||||
params: Partial<{
|
||||
pageNo: string;
|
||||
pageSize: string;
|
||||
searchKeyword: string;
|
||||
}>
|
||||
) {
|
||||
params.pageNo = params.pageNo || '1';
|
||||
params.pageSize = params.pageSize || '30';
|
||||
const accessToken = await getAccessToken();
|
||||
const resp = await post('/web/brand/list', accessToken, params);
|
||||
return resp.result.result.map((item) => ({
|
||||
@@ -131,7 +159,7 @@ async function fetchCityList(keyword = '') {
|
||||
// so we need to fetch all city items and then extract styles from them
|
||||
async function fetchStyleList(keyword = '') {
|
||||
const resp = await fetchParams();
|
||||
let styles = resp.result.flatMap((item) => item.styles);
|
||||
let styles = resp.result.flatMap((item) => item.styles) as Array<{ key: string; showName: string }>;
|
||||
styles = uniqBy(styles, 'key');
|
||||
styles = sortBy(styles, 'key');
|
||||
return styles
|
||||
@@ -143,7 +171,7 @@ async function fetchStyleList(keyword = '') {
|
||||
}));
|
||||
}
|
||||
|
||||
async function fetchDictionary(cityCode, showStyle) {
|
||||
async function fetchDictionary(cityCode: string, showStyle: string) {
|
||||
const resp = await fetchParams();
|
||||
const target = resp.result.find((item) => item.cityCode === cityCode);
|
||||
if (!target) {
|
||||
@@ -155,4 +183,4 @@ async function fetchDictionary(cityCode, showStyle) {
|
||||
};
|
||||
}
|
||||
|
||||
export { fetchActivityList, fetchCityList, fetchStyleList, fetchPerformerList, fetchPerformerInfo, fetchBrandList, fetchBrandInfo, fetchDictionary };
|
||||
export { fetchActivityList, fetchCityList, fetchStyleList, fetchPerformerList, fetchPerformerInfo, fetchSiteList, fetchSiteInfo, fetchBrandList, fetchBrandInfo, fetchDictionary };
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import { Data, Route } from '@/types';
|
||||
import { TITLE, HOST } from './const';
|
||||
import { fetchActivityList, fetchSiteInfo } from './service';
|
||||
import { Context } from 'hono';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/site/:siteId',
|
||||
categories: ['shopping'],
|
||||
example: '/showstart/site/3583',
|
||||
parameters: { siteId: '演出场地 (编号)' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['www.showstart.com/venue/:id'],
|
||||
},
|
||||
],
|
||||
name: '按场地 - 演出更新',
|
||||
maintainers: ['lchtao26'],
|
||||
handler,
|
||||
description: `:::tip
|
||||
- 演出场地 ID 查询: \`/showstart/search/site/:keyword\`, 如: [https://rsshub.app/showstart/search/site/酒球会](https://rsshub.app/showstart/search/site/酒球会)
|
||||
:::`,
|
||||
};
|
||||
|
||||
async function handler(ctx: Context): Promise<Data> {
|
||||
const siteId = Number.parseInt(ctx.req.param('siteId')).toString();
|
||||
const [activityList, siteInfo] = await Promise.all([fetchActivityList({ siteId }), fetchSiteInfo({ siteId })]);
|
||||
return {
|
||||
title: `${TITLE} - ${siteInfo.name}`,
|
||||
description: siteInfo.address,
|
||||
link: HOST,
|
||||
item: activityList,
|
||||
};
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
import got from '@/utils/got';
|
||||
import md5 from '@/utils/md5';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
|
||||
const uuid = (length = 20) => {
|
||||
const e = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' + Date.now();
|
||||
const r = [];
|
||||
const r: string[] = [];
|
||||
for (let i = 0; i < length; i++) {
|
||||
r.push(e.charAt(Math.floor(Math.random() * e.length)));
|
||||
}
|
||||
@@ -35,10 +35,11 @@ const getAccessToken = async () => {
|
||||
return cookieMap.get('accessToken');
|
||||
};
|
||||
|
||||
const post = async (requestPath, accessToken = md5(Date.now().toString()), payload) => {
|
||||
const post = async (requestPath: string, accessToken = md5(Date.now().toString()), payload?: any) => {
|
||||
const traceId = uuid(32) + Date.now();
|
||||
|
||||
const { data: response } = await got.post(`https://www.showstart.com/api${requestPath}`, {
|
||||
const response = await ofetch(`https://www.showstart.com/api${requestPath}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
cdeviceinfo: encodeURIComponent(JSON.stringify(devioceInfo)),
|
||||
cdeviceno: cookieMap.get('token'),
|
||||
@@ -53,14 +54,14 @@ const post = async (requestPath, accessToken = md5(Date.now().toString()), paylo
|
||||
cusname: '',
|
||||
cusut: '',
|
||||
cversion: '999',
|
||||
},
|
||||
json: payload,
|
||||
} as HeadersInit,
|
||||
body: payload,
|
||||
});
|
||||
|
||||
return response;
|
||||
};
|
||||
|
||||
function sortBy(items, key) {
|
||||
function sortBy(items: any[], key: string) {
|
||||
return items.sort((a, b) => {
|
||||
if (a[key] < b[key]) {
|
||||
return -1;
|
||||
@@ -72,7 +73,7 @@ function sortBy(items, key) {
|
||||
});
|
||||
}
|
||||
|
||||
function uniqBy(items, key) {
|
||||
function uniqBy(items: any[], key: string) {
|
||||
const set = new Set();
|
||||
return items.filter((item) => {
|
||||
if (set.has(item[key])) {
|
||||
|
||||
Reference in New Issue
Block a user