Skip to content

Commit 636a23a

Browse files
committed
Add suspect-edit and suspect-end calls
1 parent ffc676b commit 636a23a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/actions.ts

+40
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,42 @@ export const actions: {[k: string]: QueryHandler} = {
11011101
}
11021102
return {success: true};
11031103
},
1104+
async 'suspects/edit'(params) {
1105+
if (this.getIp() !== Config.restartip) {
1106+
throw new ActionError("Access denied.");
1107+
}
1108+
const id = toID(params.format);
1109+
if (!id) throw new ActionError("No format ID specified.");
1110+
const suspect = await tables.suspects.get(id);
1111+
if (!suspect) throw new ActionError("There is no ongoing suspect for " + id);
1112+
let reqs;
1113+
try {
1114+
reqs = JSON.parse(params.reqs || "");
1115+
for (const k in reqs) {
1116+
if (!['coil', 'elo', 'gxe'].includes(k)) {
1117+
throw new Error("Invalid req type: " + k);
1118+
}
1119+
if (reqs[k]) {
1120+
reqs[k] = Number(reqs[k]);
1121+
if (isNaN(reqs[k])) {
1122+
throw new Error("Req values must be numbers.");
1123+
}
1124+
} else {
1125+
reqs[k] = null;
1126+
}
1127+
}
1128+
} catch (e: any) {
1129+
throw new ActionError("Invalid reqs sent: " + e.message);
1130+
}
1131+
await tables.suspects.update(id, reqs);
1132+
await smogonFetch("tools/api/suspect-edit", "POST", {
1133+
url: params.url,
1134+
date: suspect.start_date,
1135+
format: id,
1136+
reqs,
1137+
});
1138+
return {success: true};
1139+
},
11041140
async 'suspects/end'(params) {
11051141
if (this.getIp() !== Config.restartip) {
11061142
throw new ActionError("Access denied.");
@@ -1110,6 +1146,10 @@ export const actions: {[k: string]: QueryHandler} = {
11101146
const suspect = await tables.suspects.get(id);
11111147
if (!suspect) throw new ActionError("There is no ongoing suspect for " + id);
11121148
await tables.suspects.delete(id);
1149+
await smogonFetch("tools/api/suspect-end", "POST", {
1150+
formatid: id,
1151+
time: suspect.start_date,
1152+
});
11131153
return {success: true};
11141154
},
11151155
async 'suspects/verify'(params) {

0 commit comments

Comments
 (0)