Add replay batch endpoint (#28)
Some checks failed
Node.js CI / build (18.x) (push) Has been cancelled
Node.js CI / build (20.x) (push) Has been cancelled

This commit is contained in:
Michael Gallaspy 2025-04-03 08:04:02 -07:00 committed by GitHub
parent 574a2e79fe
commit 9d59f10859
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -1025,7 +1025,14 @@ export const actions: { [k: string]: QueryHandler } = {
}
return { password: pw };
},
async 'replays/batch'(params) {
if (!params.ids) {
throw new ActionError("Invalid batch replay request, must provide ids");
}
const ids = params.ids.split(',');
if (ids.length > 51) throw new ActionError(`Limit 51 IDs (you have ${ids.length}).`);
return Replays.getBatch(ids);
},
// sent by ps server
async 'smogon/validate'(params) {
if (this.getIp() !== Config.restartip) {

View File

@ -232,6 +232,9 @@ export const Replays = new class {
SQL`uploadtime, id, format, players, rating`
)`WHERE private = 0 ORDER BY uploadtime DESC LIMIT 51`.then(this.toReplays);
}
getBatch(ids: string[]) {
return replays.selectAll()`WHERE private = 0 AND id IN (${ids}) LIMIT 51`.then(this.toReplays);
}
};
export default Replays;