diff --git a/src/actions.ts b/src/actions.ts index 3448155..1c78ad9 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 = 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 8f03c9d..6113c76 100644 --- a/src/replays.ts +++ b/src/replays.ts @@ -233,6 +233,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;