Skip to content

Commit

Permalink
Update for new Replays database
Browse files Browse the repository at this point in the history
Catastrophic database failure is always a great time to migrate
onto a nicer schema...
  • Loading branch information
Zarel committed Dec 7, 2023
1 parent 113b407 commit 58818ad
Show file tree
Hide file tree
Showing 10 changed files with 610 additions and 471 deletions.
25 changes: 19 additions & 6 deletions config/config-example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MySQL DB settings.
/** For the login and ladder databases */
exports.mysql = {
charset: "utf8",
database: "ps",
Expand All @@ -9,6 +9,24 @@ exports.mysql = {
prefix: "ntbb_",
};

/** For the replay databases */
exports.replaysdb = {
charset: "utf8",
database: "ps",
password: "",
host: 'localhost',
user: "root",
socketPath: '',
prefix: "ntbb_",
};

/**
* For the friends database
*
* @type {import('pg').PoolConfig | null}
*/
exports.postgres = null;

/** For 2FA verification. */
exports.gapi_clientid = '';

Expand Down Expand Up @@ -155,8 +173,3 @@ exports.standings = {
"30": "Permaban",
"100": "Disabled",
};

/**
* @type {import('pg').PoolConfig | null}
*/
exports.postgres = null;
134 changes: 67 additions & 67 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"bcrypt": "^5.0.1",
"eslint-plugin-import": "^2.24.2",
"google-auth-library": "^3.1.2",
"mysql2": "^2.3.3",
"pg": "^8.10.0",
"mysql2": "^3.6.5",
"pg": "^8.11.3",
"pm2": "^5.1.2",
"testcontainers": "^9.1.1"
},
Expand Down
78 changes: 44 additions & 34 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,41 +172,43 @@ export const actions: {[k: string]: QueryHandler} = {
},

async prepreplay(params) {

Check failure on line 174 in src/actions.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Async method 'prepreplay' has no 'await' expression

Check warning on line 174 in src/actions.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

'params' is defined but never used
const server = await this.getServer(true);
if (!server) {
// legacy error
return {errorip: this.getIp()};
}

const extractedFormatId = /^([a-z0-9]+)-[0-9]+$/.exec(`${params.id}`)?.[1];
const formatId = /^([a-z0-9]+)$/.exec(`${params.format}`)?.[1];
if (
// the server must send all the required values
!params.id || !params.format || !params.loghash || !params.p1 || !params.p2 ||
// player usernames cannot be longer than 18 characters
params.p1.length > 18 || params.p2.length > 18 ||
// the battle ID must be valid
!extractedFormatId ||
// the format from the battle ID must match the format ID
formatId !== extractedFormatId
) {
return 0;
}

if (server.id !== Config.mainserver) {
params.id = server.id + '-' + params.id;
}
params.serverid = server.id;

const result = await Replays.prep(params);

this.setPrefix(''); // No need for prefix since only usable by server.
return result;
return 'currently unavailable';
// const server = await this.getServer(true);
// if (!server) {
// // legacy error
// return {errorip: this.getIp()};
// }

// const extractedFormatId = /^([a-z0-9]+)-[0-9]+$/.exec(`${params.id}`)?.[1];
// const formatId = /^([a-z0-9]+)$/.exec(`${params.format}`)?.[1];
// if (
// // the server must send all the required values
// !params.id || !params.format || !params.loghash || !params.p1 || !params.p2 ||
// // player usernames cannot be longer than 18 characters
// params.p1.length > 18 || params.p2.length > 18 ||
// // the battle ID must be valid
// !extractedFormatId ||
// // the format from the battle ID must match the format ID
// formatId !== extractedFormatId
// ) {
// return 0;
// }

// if (server.id !== Config.mainserver) {
// params.id = server.id + '-' + params.id;
// }
// params.serverid = server.id;

// const result = await Replays.prep(params);

// this.setPrefix(''); // No need for prefix since only usable by server.
// return result;
},

uploadreplay(params) {

Check warning on line 208 in src/actions.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

'params' is defined but never used
this.setHeader('Content-Type', 'text/plain; charset=utf-8');
return Replays.upload(params, this);
return 'currently unavailable';
// this.setHeader('Content-Type', 'text/plain; charset=utf-8');
// return Replays.upload(params, this);
},

async invalidatecss() {
Expand Down Expand Up @@ -715,8 +717,12 @@ export const actions: {[k: string]: QueryHandler} = {
if (params.sort && params.sort !== 'rating' && params.sort !== 'date') {
throw new ActionError('Sort must be "rating" or "date"');
}
let username = (params.username ||= params.user);
if (!params.username2 && username?.includes(',')) {
[username, params.username2] = username.split(',');
}
const search = {
username: toID(params.username || params.user),
username: toID(username),
username2: toID(params.username2),
format: toID(params.format),
page: Number(params.page || '1'),
Expand All @@ -735,8 +741,12 @@ export const actions: {[k: string]: QueryHandler} = {
if (params.sort && params.sort !== 'rating' && params.sort !== 'date') {
throw new ActionError('Sort must be "rating" or "date"');
}
let username = (params.username ||= params.user);
if (!params.username2 && username?.includes(',')) {
[username, params.username2] = username.split(',');
}
const search = {
username: toID(params.username || params.user),
username: toID(username),
username2: toID(params.username2),
format: toID(params.format),
page: Number(params.page || '1'),
Expand Down
Loading

0 comments on commit 58818ad

Please sign in to comment.