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 ---------
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
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',
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
import { Route } from '@/types';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
|
||||
import { parseFilterStr } from './util';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/events/:filter?',
|
||||
name: 'Events',
|
||||
url: 'app.questn.com',
|
||||
maintainers: ['cxheng315'],
|
||||
example: '/questn/events',
|
||||
parameters: {
|
||||
filter: 'Filter string',
|
||||
},
|
||||
description: `
|
||||
:::tip
|
||||
|
||||
Filter parameters:
|
||||
- category: 100: trending, 200: newest, 300: top
|
||||
- status_filter: 0: all, 100: available, 400: missed
|
||||
- community_filter: 0: all community, 100: verified, 200: followed
|
||||
- rewards_filter: 0: all rewards, 100: nft, 200: token, 400: whitelist
|
||||
- chain_filter: 0: all chains, 1: ethereum, 56: bsc, 137: polygon, 42161: arb, 10: op, 324: zksync, 43114: avax
|
||||
- search: 'Search keyword',
|
||||
- count: 'Number of events to fetch',
|
||||
- page: 'Page number',
|
||||
:::`,
|
||||
categories: ['other'],
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['app.questn.com/explore'],
|
||||
target: '/events/:category?/:status_filter?/:community_filter?/:reward_filter?/:chain_filter?/:search?/:count?/:page?',
|
||||
},
|
||||
],
|
||||
handler,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const url = 'https://api.questn.com/consumer/explore/list/';
|
||||
|
||||
const parsedFilter: { category?: string; status_filter?: string; community_filter?: string; reward_filter?: string; chain_filter?: string; search?: string; count?: string; page?: string } = parseFilterStr(
|
||||
ctx.req.param('filter')
|
||||
);
|
||||
|
||||
const params = {
|
||||
category: parsedFilter.category || '200',
|
||||
status_filter: parsedFilter.status_filter || '100',
|
||||
community_filter: parsedFilter.community_filter || '0',
|
||||
rewards_filter: parsedFilter.reward_filter || '0',
|
||||
chain_filter: parsedFilter.chain_filter || '0',
|
||||
search: parsedFilter.search || '',
|
||||
count: parsedFilter.count || ctx.req.query('limit') || '20',
|
||||
page: parsedFilter.page || '1',
|
||||
};
|
||||
|
||||
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 Events',
|
||||
link: 'https://app.questn.com/explore',
|
||||
description: 'A Quest Protocol Dedicated to DePIN and AI Training',
|
||||
image: 'https://app.questn.com/static/svgs/logo-white.svg',
|
||||
logo: 'https://app.questn.com/static/svgs/logo-white.svg',
|
||||
author: 'QuestN',
|
||||
item:
|
||||
items && items.length > 0
|
||||
? items
|
||||
: [
|
||||
{
|
||||
title: 'No events found',
|
||||
description: 'No events found',
|
||||
link: 'https://app.questn.com/explore',
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import type { Namespace } from '@/types';
|
||||
|
||||
export const namespace: Namespace = {
|
||||
name: 'QuestN',
|
||||
url: 'app.questn.com',
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
const parseFilterStr = (filterStr) => {
|
||||
const filters = {};
|
||||
if (!filterStr) {
|
||||
return filters;
|
||||
}
|
||||
const filterPairs = filterStr.split('&'); // Split by '&'
|
||||
|
||||
for (const pair of filterPairs) {
|
||||
const [key, value] = pair.split('='); // Split by '='
|
||||
filters[key] = value;
|
||||
}
|
||||
|
||||
return filters;
|
||||
};
|
||||
|
||||
export { parseFilterStr };
|
||||
Reference in New Issue
Block a user