diff --git a/src/actions.ts b/src/actions.ts index 3448155..ccb575d 100644 --- a/src/actions.ts +++ b/src/actions.ts @@ -904,7 +904,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: string[] = params.ids.split(',').slice(0, 51); + const results = await Replays.getBatch(ids); + return results; + }, // sent by ps server async 'smogon/validate'(params) { if (this.getIp() !== Config.restartip) { diff --git a/src/replays.ts b/src/replays.ts index 8f03c9d..37ac258 100644 --- a/src/replays.ts +++ b/src/replays.ts @@ -233,6 +233,10 @@ 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;