Skip to content

Commit

Permalink
Add replays/edit action
Browse files Browse the repository at this point in the history
  • Loading branch information
mia-pi-git committed Oct 27, 2023
1 parent d63274a commit 8ead756
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,43 @@ export const actions: {[k: string]: QueryHandler} = {
if (!search.page) search.page = 1;
return Replays.search(search);
},
async 'replays/edit'(params) {
if (!this.user.isLeader()) throw new ActionError(`Access denied.`);
const id = toID(params.id);
if (!id) throw new ActionError(`No replay ID was provided.`);
const replay = await tables.replays.get(id);
if (!replay) throw new ActionError(`Replay ${id} not found.`);
let pw;
switch (Number(params.private)) {
case 3:
await tables.replays.update(id, {
password: null,
private: 3,
});
break;
case 2: // private [1], no pass
await tables.replays.update(id, {
private: 1,
password: null,
});
break;
case 1:
if (!replay.password) replay.password = Replays.generatePassword();
pw = replay.password;
await tables.replays.update(id, {
private: 1,
password: replay.password,
});
break;
default:
await tables.replays.update(id, {
password: null,
private: 0,
});
break;
}
return {password: pw};
},
};

if (Config.actions) {
Expand Down
7 changes: 7 additions & 0 deletions src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class User {
name = 'Guest';
id = 'guest';
loggedIn = '';
group = 0;
constructor(name?: string) {
if (name) this.setName(name);
}
Expand All @@ -42,6 +43,11 @@ export class User {
isSysop() {
return Config.sysops.includes(this.id);
}
isLeader() {
// 2 - admin with 2fa
// 6 - admin (no 2fa)
return [2, 6].includes(this.group);
}
}

export class Session {
Expand Down Expand Up @@ -474,6 +480,7 @@ export class Session {
// okay, legit session ID - you're logged in now.
const user = new User();
user.login(cookieName as string);
user.group = (await users.get(user.id))?.group || 0;

this.sidhash = sid;
this.session = session;
Expand Down

0 comments on commit 8ead756

Please sign in to comment.