From 9d59f108594cfb8146fbc96ce5975bc47b9c2b41 Mon Sep 17 00:00:00 2001 From: Michael Gallaspy Date: Thu, 3 Apr 2025 08:04:02 -0700 Subject: [PATCH] Add replay batch endpoint (#28) --- src/actions.ts | 9 ++++++++- src/replays.ts | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/actions.ts b/src/actions.ts index 3a5ea59..d6b3822 100644 --- a/src/actions.ts +++ b/src/actions.ts @@ -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) { diff --git a/src/replays.ts b/src/replays.ts index 92f4c60..fe1333f 100644 --- a/src/replays.ts +++ b/src/replays.ts @@ -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;