Skip to content

Commit

Permalink
Add replay search endpoints for New Replays
Browse files Browse the repository at this point in the history
  • Loading branch information
mia-pi-git committed Oct 26, 2023
1 parent 1272268 commit f09edd0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,38 @@ export const actions: {[k: string]: QueryHandler} = {
throw new ActionError("Failed to fetch team. Please try again later.");
}
},
async 'replays/search'(params) {
const search = {
username: toID(params.username),
username2: toID(params.username2),
format: toID(params.format),
page: Number(params.page),
byRating: !!params.byRating,
};
if (isNaN(search.page) || search.page !== Math.trunc(search.page)) {
throw new ActionError(`Invalid page number: ${params.page}`);
}
return Replays.search(search);
},
async 'replays/searchprivate'(params) {
this.verifyCrossDomainRequest();
if (!this.user.loggedIn) throw new ActionError(`Access denied.`);
const search = {
username: toID(params.username),
username2: toID(params.username2),
format: toID(params.format),
page: Number(params.page),
byRating: !!params.byRating,
isPrivate: true,
};
if (!(this.user.isSysop() || [search.username, search.username2].includes(this.user.id))) {
throw new ActionError(`Access denied.`);
}
if (isNaN(search.page) || search.page !== Math.trunc(search.page)) {
throw new ActionError(`Invalid page number: ${params.page}`);
}
return Replays.search(search);
},
};

if (Config.actions) {
Expand Down
5 changes: 4 additions & 1 deletion src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export class User {
this.setName('Guest');
this.loggedIn = '';
}
isSysop() {
return Config.sysops.includes(this.id);
}
}

export class Session {
Expand Down Expand Up @@ -201,7 +204,7 @@ export class Session {
if (user.loggedIn === userid) {
// already logged in
userType = '2';
if (Config.sysops.includes(user.id)) {
if (user.isSysop()) {
userType = '3';
} else {
const customType = (Config as any).getUserType?.call(
Expand Down

0 comments on commit f09edd0

Please sign in to comment.