feat: cleaner fetch blitz func

This commit is contained in:
TrèsAbhi committed 2024-04-16 13:45:02 -05:00
1 parent 076785a9ad
commit 3e7a73c528
13 files changed
+82 -85

No files matched your search

+14 -2
View File
@@ -1,3 +1,5 @@
import { Region } from '../../constants/regions';
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
import { patientFetch } from '../blitzkrieg/patientFetch';
type BlitzResponse<Data extends object> =
@@ -58,10 +60,20 @@ async function manageQueue() {
}
}
export default function fetchBlitz<Data extends object>(url: string) {
export default function fetchBlitz<Data extends object>(
region: Region,
path: string,
params: Record<string, string | number | undefined> = {},
) {
return new Promise<Data>((resolve) => {
queue.push({
url,
url: `https://api.wotblitz.${region}/wotb/${path}/?${Object.entries({
application_id: WARGAMING_APPLICATION_ID,
...params,
})
.filter(([_, value]) => value !== undefined)
.map(([key, value]) => `${key}=${encodeURIComponent(value!)}`)
.join('&')}`,
resolve(data) {
resolve(data as Data);
},