Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add replay batch endpoint #28

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions src/replays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;