Files
blitzkit/packages/core/src/blitz/searchClansAcrossRegions.ts
T

51 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-10-13 23:20:26 -05:00
import type { ClanList } from "./clans";
2025-10-12 15:05:58 +00:00
import { fetchBlitz } from "./fetchBlitz";
2025-10-13 23:20:26 -05:00
import type { Region } from "./regions";
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([
2025-10-12 15:05:58 +00:00
fetchBlitz<ClanList>("com", "clans/list", {
2024-04-15 13:19:25 -05:00
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,
2025-10-12 15:05:58 +00:00
region: "com" as Region,
2023-11-01 11:45:19 -05:00
}))
2025-10-12 15:05:58 +00:00
.splice(0, normalizedLimit)
2023-05-20 01:22:20 +00:00
),
2025-10-12 15:05:58 +00:00
fetchBlitz<ClanList>("eu", "clans/list", {
2024-04-15 13:19:25 -05:00
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,
2025-10-12 15:05:58 +00:00
region: "eu" as Region,
2023-11-01 11:45:19 -05:00
}))
2025-10-12 15:05:58 +00:00
.splice(0, normalizedLimit)
2023-05-20 01:22:20 +00:00
),
2025-10-12 15:05:58 +00:00
fetchBlitz<ClanList>("asia", "clans/list", {
2024-04-15 13:19:25 -05:00
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,
2025-10-12 15:05:58 +00:00
region: "asia" as Region,
2023-11-01 11:45:19 -05:00
}))
2025-10-12 15:05:58 +00:00
.splice(0, normalizedLimit)
2023-05-20 01:22:20 +00:00
),
])
)
.filter(Boolean)
.flat();
2023-05-16 02:02:50 +00:00
}