Skip to content

Commit

Permalink
style: eslint changes
Browse files Browse the repository at this point in the history
  • Loading branch information
binaryoverload committed Feb 3, 2025
1 parent 2862fed commit 3a2526d
Show file tree
Hide file tree
Showing 102 changed files with 2,357 additions and 5,115 deletions.
7 changes: 7 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@ export default [
...globals.node
}
}
},
{
rules: {
// * Because mii-js is imported via GitHub, it will not be resolved by eslint
// TODO: Remove this rule when mii-js is published to npm
'import/no-unresolved': ['error', { ignore: ['mii-js'] }]
}
}
];
2 changes: 1 addition & 1 deletion migrations/add-console-type-to-nex-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ database.connect().then(async function () {
console.log('Migrated accounts');

process.exit(0);
});
});
3 changes: 1 addition & 2 deletions migrations/add-missing-friendcodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ database.connect().then(async function () {
});

for (const nexAccount of nexAccountsToBeChanged) {

if (!nexAccount.friend_code) {
const pid = nexAccount.pid;
const pidBuffer = Buffer.alloc(4);
Expand All @@ -33,4 +32,4 @@ database.connect().then(async function () {
console.log('Migrated accounts');

process.exit(0);
});
});
3 changes: 1 addition & 2 deletions migrations/add-missing-server-aes-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ database.connect().then(async function () {
});

for (const server of servers) {

if (!server.aes_key) {
server.aes_key = crypto.randomBytes(32).toString('hex');

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

process.exit(0);
});
});
6,668 changes: 1,948 additions & 4,720 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
},
"devDependencies": {
"@hcaptcha/types": "^1.0.3",
"@pretendonetwork/eslint-config": "^0.0.7",
"@pretendonetwork/eslint-config": "^0.0.8",
"@types/bcrypt": "^5.0.0",
"@types/buffer-crc32": "^0.2.2",
"@types/cors": "^2.8.13",
Expand All @@ -85,4 +85,4 @@
"ndarray": "^1.0.19",
"typescript": "^4.9.5"
}
}
}
65 changes: 34 additions & 31 deletions pnid-scrub.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
const { confirm, input } = require('@inquirer/prompts');
const { connect } = require('./dist/database');
const { PNID } = require('./dist/models/pnid');
const { confirm, input } = require('@inquirer/prompts');

async function bootstrap() {
await connect();

const pnidName = await input({ message: 'What PNID do you want to delete?' });
const pnid = await PNID.findOne({ username:pnidName.trim() });
if (!pnid) {
console.log("Could not find PNID");
process.exit(1);
}

console.log('Before:', pnid);

if (pnid.deleted) {
console.log("PNID is already marked as deleted");
process.exit(1);
}

const confirmed = await confirm({ message: 'Do you want to delete this PNID',default: false });
if (!confirmed) {
console.log("Aborted");
process.exit(1);
}

await pnid.scrub();
await pnid.save();

console.log('After:', pnid);
if (pnid.deleted) console.log("SUCCESSFULLY DELETED");
else console.log("COULD NOT DELETE");

process.exit(0);
await connect();

const pnidName = await input({ message: 'What PNID do you want to delete?' });
const pnid = await PNID.findOne({ username: pnidName.trim() });
if (!pnid) {
console.log('Could not find PNID');
process.exit(1);
}

console.log('Before:', pnid);

if (pnid.deleted) {
console.log('PNID is already marked as deleted');
process.exit(1);
}

const confirmed = await confirm({ message: 'Do you want to delete this PNID', default: false });
if (!confirmed) {
console.log('Aborted');
process.exit(1);
}

await pnid.scrub();
await pnid.save();

console.log('After:', pnid);
if (pnid.deleted) {
console.log('SUCCESSFULLY DELETED');
} else {
console.log('COULD NOT DELETE');
}

process.exit(0);
}

bootstrap();
4 changes: 2 additions & 2 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const LOCAL_CDN_BASE = `${__dirname}/../cdn`;
export async function connect(): Promise<void> {
if (!disabledFeatures.redis) {
client = redis.createClient(config.redis.client);
client.on('error', (err) => console.log('Redis Client Error', err));
client.on('error', err => console.log('Redis Client Error', err));

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

export async function setLocalCDNFile(name: string, value: Buffer): Promise<void> {
await setCachedFile(`local_cdn:${name}`, value);
}
}
21 changes: 13 additions & 8 deletions src/config-manager.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import fs from 'fs-extra';
import mongoose from 'mongoose';
import dotenv from 'dotenv';
import isValidHostname from 'is-valid-hostname';
import { LOG_INFO, LOG_WARN, LOG_ERROR, formatHostnames } from '@/logger';
import { type Config, domainServices, optionalDomainServices } from '@/types/common/config';
import { domainServices, optionalDomainServices } from '@/types/common/config';
import type mongoose from 'mongoose';
import type { Config } from '@/types/common/config';

dotenv.config();

Expand Down Expand Up @@ -74,9 +75,9 @@ export const config: Config = {
grpc: {
master_api_keys: {
account: process.env.PN_ACT_CONFIG_GRPC_MASTER_API_KEY_ACCOUNT || '',
api: process.env.PN_ACT_CONFIG_GRPC_MASTER_API_KEY_API || '',
api: process.env.PN_ACT_CONFIG_GRPC_MASTER_API_KEY_API || ''
},
port: Number(process.env.PN_ACT_CONFIG_GRPC_PORT || ''),
port: Number(process.env.PN_ACT_CONFIG_GRPC_PORT || '')
},
server_environment: process.env.PN_ACT_CONFIG_SERVER_ENVIRONMENT || '',
datastore: {
Expand All @@ -90,7 +91,7 @@ export const config: Config = {
datastore: (process.env.PN_ACT_CONFIG_DOMAINS_DATASTORE || 'datastore.pretendo.cc').split(','),
local_cdn: (process.env.PN_ACT_CONFIG_DOMAINS_LOCAL_CDN || '').split(','),
nasc: (process.env.PN_ACT_CONFIG_DOMAINS_NASC || 'nasc.pretendo.cc').split(','),
nnas: (process.env.PN_ACT_CONFIG_DOMAINS_NNAS || 'c.account.pretendo.cc,account.pretendo.cc').split(','),
nnas: (process.env.PN_ACT_CONFIG_DOMAINS_NNAS || 'c.account.pretendo.cc,account.pretendo.cc').split(',')
}
};

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

for (const domain of uniqueDomains) {
isValidHostname(domain) ? validDomains.push(domain) : invalidDomains.push(domain);
if (isValidHostname(domain)) {
validDomains.push(domain);
} else {
invalidDomains.push(domain);
}
}

if (validDomains.length === 0 && !optionalDomainServices.includes(service)) {
Expand Down Expand Up @@ -230,7 +235,7 @@ if (disabledFeatures.s3) {
if (disabledFeatures.redis) {
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.');
}
}
}
}

if (!config.aes_key) {
Expand Down Expand Up @@ -270,4 +275,4 @@ if (!config.datastore.signature_secret) {
if (!configValid) {
LOG_ERROR('Config is invalid. Exiting');
process.exit(0);
}
}
30 changes: 18 additions & 12 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { PNID } from '@/models/pnid';
import { Server } from '@/models/server';
import { LOG_ERROR } from '@/logger';
import { config } from '@/config-manager';
import { HydratedPNIDDocument } from '@/types/mongoose/pnid';
import { IDeviceAttribute } from '@/types/mongoose/device-attribute';
import { HydratedServerDocument } from '@/types/mongoose/server';
import { PNIDProfile } from '@/types/services/nnas/pnid-profile';
import { ConnectionData } from '@/types/services/api/connection-data';
import { ConnectionResponse } from '@/types/services/api/connection-response';
import { DiscordConnectionData } from '@/types/services/api/discord-connection-data';
import type { HydratedPNIDDocument } from '@/types/mongoose/pnid';
import type { IDeviceAttribute } from '@/types/mongoose/device-attribute';
import type { HydratedServerDocument } from '@/types/mongoose/server';
import type { PNIDProfile } from '@/types/services/nnas/pnid-profile';
import type { ConnectionData } from '@/types/services/api/connection-data';
import type { ConnectionResponse } from '@/types/services/api/connection-response';
import type { DiscordConnectionData } from '@/types/services/api/discord-connection-data';

const connection_string = config.mongoose.connection_string;
const options = config.mongoose.options;
Expand Down Expand Up @@ -202,7 +202,7 @@ export async function getPNIDProfileJSONByPID(pid: number): Promise<PNIDProfile
}
},
name: pnid.mii.name,
primary: pnid.mii.primary ? 'Y' : 'N',
primary: pnid.mii.primary ? 'Y' : 'N'
},
region: pnid.region,
tz_name: pnid.timezone.name,
Expand All @@ -221,7 +221,9 @@ export async function getServerByGameServerID(gameServerID: string, accessMode:

for (const mode of searchModes) {
const server = servers.find(s => s.access_mode === mode);
if (server) return server;
if (server) {
return server;
}
}

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

for (const mode of searchModes) {
const server = servers.find(s => s.access_mode === mode);
if (server) return server;
if (server) {
return server;
}
}

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

for (const mode of searchModes) {
const server = servers.find(s => s.access_mode === mode);
if (server) return server;
if (server) {
return server;
}
}

return null;
Expand Down Expand Up @@ -306,4 +312,4 @@ export async function removePNIDConnectionDiscord(pnid: HydratedPNIDDocument): P
app: 'api',
status: 200
};
}
}
2 changes: 1 addition & 1 deletion src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ export function LOG_INFO(input: string): void {

export function formatHostnames(hostnames: string[]): string {
return hostnames.map(d => `'${d}'`).join(', ');
}
}
4 changes: 2 additions & 2 deletions src/mailer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'node:fs';
import nodemailer from 'nodemailer';
import * as aws from '@aws-sdk/client-ses';
import { config, disabledFeatures } from '@/config-manager';
import { MailerOptions } from '@/types/common/mailer-options';
import type { MailerOptions } from '@/types/common/mailer-options';

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

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

let html = confirmation ? confirmationEmailTemplate : genericEmailTemplate;

Expand Down
6 changes: 3 additions & 3 deletions src/middleware/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import express from 'express';
import { getValueFromHeaders } from '@/util';
import { getPNIDByTokenAuth } from '@/database';
import type express from 'express';

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

request.pnid = pnid;
} catch (error) {
// TODO - Log error
console.error('Failed to get PNID: ', error);
}

return next();
}

export default APIMiddleware;
export default APIMiddleware;
4 changes: 2 additions & 2 deletions src/middleware/cemu.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import express from 'express';
import type express from 'express';

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

export default CemuMiddleware;
export default CemuMiddleware;
10 changes: 5 additions & 5 deletions src/middleware/client-header.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import express from 'express';
import xmlbuilder from 'xmlbuilder';
import { getValueFromHeaders } from '@/util';
import type express from 'express';

const VALID_CLIENT_ID_SECRET_PAIRS: Record<string, string> = {
// * 'Key' is the client ID, 'Value' is the client secret
'a2efa818a34fa16b8afbc8a74eba3eda': 'c91cdb5658bd4954ade78533a339cf9a', // * Possibly WiiU exclusive?
'daf6227853bcbdce3d75baee8332b': '3eff548eac636e2bf45bb7b375e7b6b0', // * Possibly 3DS exclusive?
'ea25c66c26b403376b4c5ed94ab9cdea': 'd137be62cb6a2b831cad8c013b92fb55', // * Possibly 3DS exclusive?
a2efa818a34fa16b8afbc8a74eba3eda: 'c91cdb5658bd4954ade78533a339cf9a', // * Possibly WiiU exclusive?
daf6227853bcbdce3d75baee8332b: '3eff548eac636e2bf45bb7b375e7b6b0', // * Possibly 3DS exclusive?
ea25c66c26b403376b4c5ed94ab9cdea: 'd137be62cb6a2b831cad8c013b92fb55' // * Possibly 3DS exclusive?
};

function nintendoClientHeaderCheck(request: express.Request, response: express.Response, next: express.NextFunction): void {
Expand Down Expand Up @@ -39,4 +39,4 @@ function nintendoClientHeaderCheck(request: express.Request, response: express.R
return next();
}

export default nintendoClientHeaderCheck;
export default nintendoClientHeaderCheck;
Loading

0 comments on commit 3a2526d

Please sign in to comment.