Skip to content

Commit

Permalink
Add suspect-edit and suspect-end calls
Browse files Browse the repository at this point in the history
  • Loading branch information
mia-pi-git committed Nov 1, 2024
1 parent ffc676b commit 636a23a
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,42 @@ export const actions: {[k: string]: QueryHandler} = {
}
return {success: true};
},
async 'suspects/edit'(params) {
if (this.getIp() !== Config.restartip) {
throw new ActionError("Access denied.");
}
const id = toID(params.format);
if (!id) throw new ActionError("No format ID specified.");
const suspect = await tables.suspects.get(id);
if (!suspect) throw new ActionError("There is no ongoing suspect for " + id);
let reqs;
try {
reqs = JSON.parse(params.reqs || "");
for (const k in reqs) {
if (!['coil', 'elo', 'gxe'].includes(k)) {
throw new Error("Invalid req type: " + k);
}
if (reqs[k]) {
reqs[k] = Number(reqs[k]);
if (isNaN(reqs[k])) {
throw new Error("Req values must be numbers.");
}
} else {
reqs[k] = null;
}
}
} catch (e: any) {
throw new ActionError("Invalid reqs sent: " + e.message);
}
await tables.suspects.update(id, reqs);
await smogonFetch("tools/api/suspect-edit", "POST", {
url: params.url,
date: suspect.start_date,
format: id,
reqs,
});
return {success: true};
},
async 'suspects/end'(params) {
if (this.getIp() !== Config.restartip) {
throw new ActionError("Access denied.");
Expand All @@ -1110,6 +1146,10 @@ export const actions: {[k: string]: QueryHandler} = {
const suspect = await tables.suspects.get(id);
if (!suspect) throw new ActionError("There is no ongoing suspect for " + id);
await tables.suspects.delete(id);
await smogonFetch("tools/api/suspect-end", "POST", {
formatid: id,
time: suspect.start_date,
});
return {success: true};
},
async 'suspects/verify'(params) {
Expand Down

0 comments on commit 636a23a

Please sign in to comment.