@@ -1101,6 +1101,42 @@ export const actions: {[k: string]: QueryHandler} = {
1101
1101
}
1102
1102
return { success : true } ;
1103
1103
} ,
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
+ } ,
1104
1140
async 'suspects/end' ( params ) {
1105
1141
if ( this . getIp ( ) !== Config . restartip ) {
1106
1142
throw new ActionError ( "Access denied." ) ;
@@ -1110,6 +1146,10 @@ export const actions: {[k: string]: QueryHandler} = {
1110
1146
const suspect = await tables . suspects . get ( id ) ;
1111
1147
if ( ! suspect ) throw new ActionError ( "There is no ongoing suspect for " + id ) ;
1112
1148
await tables . suspects . delete ( id ) ;
1149
+ await smogonFetch ( "tools/api/suspect-end" , "POST" , {
1150
+ formatid : id ,
1151
+ time : suspect . start_date ,
1152
+ } ) ;
1113
1153
return { success : true } ;
1114
1154
} ,
1115
1155
async 'suspects/verify' ( params ) {
0 commit comments