Skip to content

Commit 3a2526d

Browse files
style: eslint changes
1 parent 2862fed commit 3a2526d

File tree

102 files changed

+2357
-5115
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+2357
-5115
lines changed

eslint.config.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,12 @@ export default [
99
...globals.node
1010
}
1111
}
12+
},
13+
{
14+
rules: {
15+
// * Because mii-js is imported via GitHub, it will not be resolved by eslint
16+
// TODO: Remove this rule when mii-js is published to npm
17+
'import/no-unresolved': ['error', { ignore: ['mii-js'] }]
18+
}
1219
}
1320
];

migrations/add-console-type-to-nex-account.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ database.connect().then(async function () {
3131
console.log('Migrated accounts');
3232

3333
process.exit(0);
34-
});
34+
});

migrations/add-missing-friendcodes.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ database.connect().then(async function () {
1111
});
1212

1313
for (const nexAccount of nexAccountsToBeChanged) {
14-
1514
if (!nexAccount.friend_code) {
1615
const pid = nexAccount.pid;
1716
const pidBuffer = Buffer.alloc(4);
@@ -33,4 +32,4 @@ database.connect().then(async function () {
3332
console.log('Migrated accounts');
3433

3534
process.exit(0);
36-
});
35+
});

migrations/add-missing-server-aes-keys.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ database.connect().then(async function () {
1010
});
1111

1212
for (const server of servers) {
13-
1413
if (!server.aes_key) {
1514
server.aes_key = crypto.randomBytes(32).toString('hex');
1615

@@ -21,4 +20,4 @@ database.connect().then(async function () {
2120
console.log('Migrated accounts');
2221

2322
process.exit(0);
24-
});
23+
});

package-lock.json

Lines changed: 1948 additions & 4720 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
},
6565
"devDependencies": {
6666
"@hcaptcha/types": "^1.0.3",
67-
"@pretendonetwork/eslint-config": "^0.0.7",
67+
"@pretendonetwork/eslint-config": "^0.0.8",
6868
"@types/bcrypt": "^5.0.0",
6969
"@types/buffer-crc32": "^0.2.2",
7070
"@types/cors": "^2.8.13",
@@ -85,4 +85,4 @@
8585
"ndarray": "^1.0.19",
8686
"typescript": "^4.9.5"
8787
}
88-
}
88+
}

pnid-scrub.js

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,41 @@
1+
const { confirm, input } = require('@inquirer/prompts');
12
const { connect } = require('./dist/database');
23
const { PNID } = require('./dist/models/pnid');
3-
const { confirm, input } = require('@inquirer/prompts');
44

55
async function bootstrap() {
6-
await connect();
7-
8-
const pnidName = await input({ message: 'What PNID do you want to delete?' });
9-
const pnid = await PNID.findOne({ username:pnidName.trim() });
10-
if (!pnid) {
11-
console.log("Could not find PNID");
12-
process.exit(1);
13-
}
14-
15-
console.log('Before:', pnid);
16-
17-
if (pnid.deleted) {
18-
console.log("PNID is already marked as deleted");
19-
process.exit(1);
20-
}
21-
22-
const confirmed = await confirm({ message: 'Do you want to delete this PNID',default: false });
23-
if (!confirmed) {
24-
console.log("Aborted");
25-
process.exit(1);
26-
}
27-
28-
await pnid.scrub();
29-
await pnid.save();
30-
31-
console.log('After:', pnid);
32-
if (pnid.deleted) console.log("SUCCESSFULLY DELETED");
33-
else console.log("COULD NOT DELETE");
34-
35-
process.exit(0);
6+
await connect();
7+
8+
const pnidName = await input({ message: 'What PNID do you want to delete?' });
9+
const pnid = await PNID.findOne({ username: pnidName.trim() });
10+
if (!pnid) {
11+
console.log('Could not find PNID');
12+
process.exit(1);
13+
}
14+
15+
console.log('Before:', pnid);
16+
17+
if (pnid.deleted) {
18+
console.log('PNID is already marked as deleted');
19+
process.exit(1);
20+
}
21+
22+
const confirmed = await confirm({ message: 'Do you want to delete this PNID', default: false });
23+
if (!confirmed) {
24+
console.log('Aborted');
25+
process.exit(1);
26+
}
27+
28+
await pnid.scrub();
29+
await pnid.save();
30+
31+
console.log('After:', pnid);
32+
if (pnid.deleted) {
33+
console.log('SUCCESSFULLY DELETED');
34+
} else {
35+
console.log('COULD NOT DELETE');
36+
}
37+
38+
process.exit(0);
3639
}
3740

3841
bootstrap();

src/cache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const LOCAL_CDN_BASE = `${__dirname}/../cdn`;
1111
export async function connect(): Promise<void> {
1212
if (!disabledFeatures.redis) {
1313
client = redis.createClient(config.redis.client);
14-
client.on('error', (err) => console.log('Redis Client Error', err));
14+
client.on('error', err => console.log('Redis Client Error', err));
1515

1616
await client.connect();
1717
}
@@ -58,4 +58,4 @@ export async function getLocalCDNFile(name: string, encoding?: BufferEncoding):
5858

5959
export async function setLocalCDNFile(name: string, value: Buffer): Promise<void> {
6060
await setCachedFile(`local_cdn:${name}`, value);
61-
}
61+
}

src/config-manager.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import fs from 'fs-extra';
2-
import mongoose from 'mongoose';
32
import dotenv from 'dotenv';
43
import isValidHostname from 'is-valid-hostname';
54
import { LOG_INFO, LOG_WARN, LOG_ERROR, formatHostnames } from '@/logger';
6-
import { type Config, domainServices, optionalDomainServices } from '@/types/common/config';
5+
import { domainServices, optionalDomainServices } from '@/types/common/config';
6+
import type mongoose from 'mongoose';
7+
import type { Config } from '@/types/common/config';
78

89
dotenv.config();
910

@@ -74,9 +75,9 @@ export const config: Config = {
7475
grpc: {
7576
master_api_keys: {
7677
account: process.env.PN_ACT_CONFIG_GRPC_MASTER_API_KEY_ACCOUNT || '',
77-
api: process.env.PN_ACT_CONFIG_GRPC_MASTER_API_KEY_API || '',
78+
api: process.env.PN_ACT_CONFIG_GRPC_MASTER_API_KEY_API || ''
7879
},
79-
port: Number(process.env.PN_ACT_CONFIG_GRPC_PORT || ''),
80+
port: Number(process.env.PN_ACT_CONFIG_GRPC_PORT || '')
8081
},
8182
server_environment: process.env.PN_ACT_CONFIG_SERVER_ENVIRONMENT || '',
8283
datastore: {
@@ -90,7 +91,7 @@ export const config: Config = {
9091
datastore: (process.env.PN_ACT_CONFIG_DOMAINS_DATASTORE || 'datastore.pretendo.cc').split(','),
9192
local_cdn: (process.env.PN_ACT_CONFIG_DOMAINS_LOCAL_CDN || '').split(','),
9293
nasc: (process.env.PN_ACT_CONFIG_DOMAINS_NASC || 'nasc.pretendo.cc').split(','),
93-
nnas: (process.env.PN_ACT_CONFIG_DOMAINS_NNAS || 'c.account.pretendo.cc,account.pretendo.cc').split(','),
94+
nnas: (process.env.PN_ACT_CONFIG_DOMAINS_NNAS || 'c.account.pretendo.cc,account.pretendo.cc').split(',')
9495
}
9596
};
9697

@@ -116,7 +117,11 @@ for (const service of domainServices) {
116117
const uniqueDomains = [...new Set(config.domains[service])];
117118

118119
for (const domain of uniqueDomains) {
119-
isValidHostname(domain) ? validDomains.push(domain) : invalidDomains.push(domain);
120+
if (isValidHostname(domain)) {
121+
validDomains.push(domain);
122+
} else {
123+
invalidDomains.push(domain);
124+
}
120125
}
121126

122127
if (validDomains.length === 0 && !optionalDomainServices.includes(service)) {
@@ -230,7 +235,7 @@ if (disabledFeatures.s3) {
230235
if (disabledFeatures.redis) {
231236
LOG_WARN('Both S3 and Redis are disabled. Large CDN files will use the in-memory cache, which may result in high memory use. Please enable S3 if you\'re running a production server.');
232237
}
233-
}
238+
}
234239
}
235240

236241
if (!config.aes_key) {
@@ -270,4 +275,4 @@ if (!config.datastore.signature_secret) {
270275
if (!configValid) {
271276
LOG_ERROR('Config is invalid. Exiting');
272277
process.exit(0);
273-
}
278+
}

src/database.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import { PNID } from '@/models/pnid';
66
import { Server } from '@/models/server';
77
import { LOG_ERROR } from '@/logger';
88
import { config } from '@/config-manager';
9-
import { HydratedPNIDDocument } from '@/types/mongoose/pnid';
10-
import { IDeviceAttribute } from '@/types/mongoose/device-attribute';
11-
import { HydratedServerDocument } from '@/types/mongoose/server';
12-
import { PNIDProfile } from '@/types/services/nnas/pnid-profile';
13-
import { ConnectionData } from '@/types/services/api/connection-data';
14-
import { ConnectionResponse } from '@/types/services/api/connection-response';
15-
import { DiscordConnectionData } from '@/types/services/api/discord-connection-data';
9+
import type { HydratedPNIDDocument } from '@/types/mongoose/pnid';
10+
import type { IDeviceAttribute } from '@/types/mongoose/device-attribute';
11+
import type { HydratedServerDocument } from '@/types/mongoose/server';
12+
import type { PNIDProfile } from '@/types/services/nnas/pnid-profile';
13+
import type { ConnectionData } from '@/types/services/api/connection-data';
14+
import type { ConnectionResponse } from '@/types/services/api/connection-response';
15+
import type { DiscordConnectionData } from '@/types/services/api/discord-connection-data';
1616

1717
const connection_string = config.mongoose.connection_string;
1818
const options = config.mongoose.options;
@@ -202,7 +202,7 @@ export async function getPNIDProfileJSONByPID(pid: number): Promise<PNIDProfile
202202
}
203203
},
204204
name: pnid.mii.name,
205-
primary: pnid.mii.primary ? 'Y' : 'N',
205+
primary: pnid.mii.primary ? 'Y' : 'N'
206206
},
207207
region: pnid.region,
208208
tz_name: pnid.timezone.name,
@@ -221,7 +221,9 @@ export async function getServerByGameServerID(gameServerID: string, accessMode:
221221

222222
for (const mode of searchModes) {
223223
const server = servers.find(s => s.access_mode === mode);
224-
if (server) return server;
224+
if (server) {
225+
return server;
226+
}
225227
}
226228

227229
return null;
@@ -237,7 +239,9 @@ export async function getServerByTitleID(titleID: string, accessMode: string): P
237239

238240
for (const mode of searchModes) {
239241
const server = servers.find(s => s.access_mode === mode);
240-
if (server) return server;
242+
if (server) {
243+
return server;
244+
}
241245
}
242246

243247
return null;
@@ -253,7 +257,9 @@ export async function getServerByClientID(clientID: string, accessMode: string):
253257

254258
for (const mode of searchModes) {
255259
const server = servers.find(s => s.access_mode === mode);
256-
if (server) return server;
260+
if (server) {
261+
return server;
262+
}
257263
}
258264

259265
return null;
@@ -306,4 +312,4 @@ export async function removePNIDConnectionDiscord(pnid: HydratedPNIDDocument): P
306312
app: 'api',
307313
status: 200
308314
};
309-
}
315+
}

src/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ export function LOG_INFO(input: string): void {
4848

4949
export function formatHostnames(hostnames: string[]): string {
5050
return hostnames.map(d => `'${d}'`).join(', ');
51-
}
51+
}

src/mailer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fs from 'node:fs';
33
import nodemailer from 'nodemailer';
44
import * as aws from '@aws-sdk/client-ses';
55
import { config, disabledFeatures } from '@/config-manager';
6-
import { MailerOptions } from '@/types/common/mailer-options';
6+
import type { MailerOptions } from '@/types/common/mailer-options';
77

88
const genericEmailTemplate = fs.readFileSync(path.join(__dirname, './assets/emails/genericTemplate.html'), 'utf8');
99
const confirmationEmailTemplate = fs.readFileSync(path.join(__dirname, './assets/emails/confirmationTemplate.html'), 'utf8');
@@ -30,7 +30,7 @@ if (!disabledFeatures.email) {
3030

3131
export async function sendMail(options: MailerOptions): Promise<void> {
3232
if (!disabledFeatures.email) {
33-
const { to, subject, username, paragraph, preview, text, link, confirmation } = options;
33+
const { to, subject, username, paragraph, preview, text, link, confirmation } = options;
3434

3535
let html = confirmation ? confirmationEmailTemplate : genericEmailTemplate;
3636

src/middleware/api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import express from 'express';
21
import { getValueFromHeaders } from '@/util';
32
import { getPNIDByTokenAuth } from '@/database';
3+
import type express from 'express';
44

55
async function APIMiddleware(request: express.Request, _response: express.Response, next: express.NextFunction): Promise<void> {
66
const authHeader = getValueFromHeaders(request.headers, 'authorization');
@@ -15,10 +15,10 @@ async function APIMiddleware(request: express.Request, _response: express.Respon
1515

1616
request.pnid = pnid;
1717
} catch (error) {
18-
// TODO - Log error
18+
console.error('Failed to get PNID: ', error);
1919
}
2020

2121
return next();
2222
}
2323

24-
export default APIMiddleware;
24+
export default APIMiddleware;

src/middleware/cemu.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import express from 'express';
1+
import type express from 'express';
22

33
function CemuMiddleware(request: express.Request, _response: express.Response, next: express.NextFunction): void {
44
const subdomain = request.subdomains.reverse().join('.');
@@ -8,4 +8,4 @@ function CemuMiddleware(request: express.Request, _response: express.Response, n
88
return next();
99
}
1010

11-
export default CemuMiddleware;
11+
export default CemuMiddleware;

src/middleware/client-header.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import express from 'express';
21
import xmlbuilder from 'xmlbuilder';
32
import { getValueFromHeaders } from '@/util';
3+
import type express from 'express';
44

55
const VALID_CLIENT_ID_SECRET_PAIRS: Record<string, string> = {
66
// * 'Key' is the client ID, 'Value' is the client secret
7-
'a2efa818a34fa16b8afbc8a74eba3eda': 'c91cdb5658bd4954ade78533a339cf9a', // * Possibly WiiU exclusive?
8-
'daf6227853bcbdce3d75baee8332b': '3eff548eac636e2bf45bb7b375e7b6b0', // * Possibly 3DS exclusive?
9-
'ea25c66c26b403376b4c5ed94ab9cdea': 'd137be62cb6a2b831cad8c013b92fb55', // * Possibly 3DS exclusive?
7+
a2efa818a34fa16b8afbc8a74eba3eda: 'c91cdb5658bd4954ade78533a339cf9a', // * Possibly WiiU exclusive?
8+
daf6227853bcbdce3d75baee8332b: '3eff548eac636e2bf45bb7b375e7b6b0', // * Possibly 3DS exclusive?
9+
ea25c66c26b403376b4c5ed94ab9cdea: 'd137be62cb6a2b831cad8c013b92fb55' // * Possibly 3DS exclusive?
1010
};
1111

1212
function nintendoClientHeaderCheck(request: express.Request, response: express.Response, next: express.NextFunction): void {
@@ -39,4 +39,4 @@ function nintendoClientHeaderCheck(request: express.Request, response: express.R
3939
return next();
4040
}
4141

42-
export default nintendoClientHeaderCheck;
42+
export default nintendoClientHeaderCheck;

0 commit comments

Comments
 (0)