Skip to content

Commit

Permalink
Ensure redundancy in suspect verification request
Browse files Browse the repository at this point in the history
  • Loading branch information
mia-pi-git committed Oct 22, 2024
1 parent eef3515 commit 1094b0a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ if (Config.coilpath) {
watchFile(Config.coilpath, () => Object.assign(coil, loadData(Config.coilpath)));
}

const redundantFetch = async (url: string, data: RequestInit, attempts = 0): Promise<void> => {

Check failure on line 69 in src/actions.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'url' is already declared in the upper scope on line 10 column 13

Check failure on line 69 in src/actions.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'url' is already declared in the upper scope on line 10 column 13
if (attempts >= 10) return;
try {
await fetch(url, data);
} catch (e: any) {
if (e.code === 400) return console.error('400 on Smogon request', e, data);
return redundantFetch(url, data, attempts++);
}
}

Check failure on line 77 in src/actions.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Missing semicolon

Check failure on line 77 in src/actions.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Missing semicolon

export const actions: {[k: string]: QueryHandler} = {
async register(params) {
Expand Down Expand Up @@ -397,14 +406,12 @@ export const actions: {[k: string]: QueryHandler} = {
reqs: {required: reqs, actual: userData},
suspectStartDate: suspects[formatid].startDate,
});
void fetch("https://www.smogon.com/tools/api/suspect-verify", {
void redundantFetch("https://www.smogon.com/tools/api/suspect-verify", {
method: 'POST',
body: new URLSearchParams({
data,
hash: await signAsync("RSA-SHA1", data, Config.privatekey),
}),
}).catch(e => {
console.error("Smogon request failed", e, {data, params});
});
}
}
Expand Down

0 comments on commit 1094b0a

Please sign in to comment.