2024-09-08 10:11:24 -05:00
|
|
|
import { fetchBlitz, Region } from '@blitzkit/core';
|
2024-09-07 23:00:56 -05:00
|
|
|
import { ClanList } from './clans';
|
2023-05-16 02:02:50 +00:00
|
|
|
|
2024-09-08 10:11:24 -05:00
|
|
|
export async function searchClansAcrossRegions(search: string, limit = 25) {
|
2023-05-20 01:22:20 +00:00
|
|
|
const trimmed = search.trim();
|
|
|
|
|
if (trimmed.length < 3 && trimmed.length > 100) return [];
|
2023-11-01 11:45:19 -05:00
|
|
|
const normalizedLimit = Math.floor(limit / 3);
|
|
|
|
|
|
|
|
|
|
// TODO: remove splice once wargaming fixes the functionality of the limit felid
|
2023-05-16 02:02:50 +00:00
|
|
|
|
2023-05-20 01:22:20 +00:00
|
|
|
return (
|
|
|
|
|
await Promise.all([
|
2024-04-15 13:19:25 -05:00
|
|
|
fetchBlitz<ClanList>('com', 'clans/list', {
|
|
|
|
|
search,
|
|
|
|
|
limit: normalizedLimit,
|
|
|
|
|
}).then((value) =>
|
2023-11-01 11:45:19 -05:00
|
|
|
value
|
|
|
|
|
.map((account) => ({
|
2023-05-16 02:02:50 +00:00
|
|
|
...account,
|
2023-09-07 03:24:07 +00:00
|
|
|
region: 'com' as Region,
|
2023-11-01 11:45:19 -05:00
|
|
|
}))
|
|
|
|
|
.splice(0, normalizedLimit),
|
2023-05-20 01:22:20 +00:00
|
|
|
),
|
2024-04-15 13:19:25 -05:00
|
|
|
fetchBlitz<ClanList>('eu', 'clans/list', {
|
|
|
|
|
search,
|
|
|
|
|
limit: normalizedLimit,
|
|
|
|
|
}).then((value) =>
|
2023-11-01 11:45:19 -05:00
|
|
|
value
|
|
|
|
|
.map((account) => ({
|
2023-05-16 02:02:50 +00:00
|
|
|
...account,
|
2023-09-07 03:24:07 +00:00
|
|
|
region: 'eu' as Region,
|
2023-11-01 11:45:19 -05:00
|
|
|
}))
|
|
|
|
|
.splice(0, normalizedLimit),
|
2023-05-20 01:22:20 +00:00
|
|
|
),
|
2024-04-15 13:19:25 -05:00
|
|
|
fetchBlitz<ClanList>('asia', 'clans/list', {
|
|
|
|
|
search,
|
|
|
|
|
limit: normalizedLimit,
|
|
|
|
|
}).then((value) =>
|
2023-11-01 11:45:19 -05:00
|
|
|
value
|
|
|
|
|
.map((account) => ({
|
2023-05-16 02:02:50 +00:00
|
|
|
...account,
|
2023-09-07 03:24:07 +00:00
|
|
|
region: 'asia' as Region,
|
2023-11-01 11:45:19 -05:00
|
|
|
}))
|
|
|
|
|
.splice(0, normalizedLimit),
|
2023-05-20 01:22:20 +00:00
|
|
|
),
|
|
|
|
|
])
|
|
|
|
|
)
|
|
|
|
|
.filter(Boolean)
|
|
|
|
|
.flat();
|
2023-05-16 02:02:50 +00:00
|
|
|
}
|