Files
RSSHub/lib/routes/questn/community.ts
T
hinusandTony 0b3fd9b19c feat(route): add QuestN (#16534)
* Add Route: QuestN

1. Add Route: community, events
2. Add utility file to parse filter string
3. Add QuestN namespace

* Update events.ts

Remove handled error condition

* Update parseFilterStr function

1. Update export method on util.ts
2. Update prarsedFilterStr variable

* Update util.ts

1. Handle condition if optional parameter : filter wasn't given(undefined)

* Update community.ts & events.ts

1. Standardize route name
2. Standardize events.ts parameters
3. Add events.ts description

* Update lib/routes/questn/events.ts

fix indent

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update community.ts

modify route parameter to meet camelCase standard

* Update community.ts

update radar source and target route to meet camelCase standard

---------
2024-08-27 23:32:28 +08:00

77 lines
2.4 KiB
TypeScript

import { Route } from '@/types';
import { parseDate } from '@/utils/parse-date';
import ofetch from '@/utils/ofetch';
export const route: Route = {
path: '/community/:communityUrl',
name: 'Community Events',
url: 'app.questn.com',
maintainers: ['cxheng315'],
example: '/questn/community/gmnetwork',
parameters: {
community_url: 'Community URL',
},
categories: ['other'],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['app.questn.com/:communityUrl'],
target: '/community/:communityUrl',
},
],
handler,
};
async function handler(ctx) {
const url = 'https://api.questn.com/consumer/explore/entity_list/';
const params = {
count: ctx.req.query('limit') || '20',
page: '1',
community_url: ctx.req.param('communityUrl') || 'questn', // default to questn
};
const response = await ofetch(`${url}?${new URLSearchParams(params)}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
const data = await response.result.data;
const items = data.map((item) => ({
title: item.title,
link: `https://app.questn.com/quest/${item.id}`,
author: item.community_info ? item.community_info.name : '',
guid: item.id,
pubDate: parseDate(item.start_time * 1000),
itunes_duration: item.end_time > 0 ? item.end_time - item.start_time : 0,
}));
return {
title: `QuestN Community - ${data[0].community_info ? data[0].community_info.name : ''} Events`,
link: `https://app.questn.com/${ctx.req.param('community_url')}`,
description: data[0].community_info ? data[0].community_info.introduction : '',
image: data[0].community_info ? data[0].community_info.logo : '',
logo: data[0].community_info ? data[0].community_info.logo : '',
item:
items && items.length > 0
? items
: [
{
title: 'No events found',
link: `https://app.questn.com/${ctx.req.param('community_url')}`,
description: 'No events found',
},
],
};
}