Finish strict mode errors

This commit is contained in:
Jonathan Barrow
2023-03-18 16:58:20 -04:00
parent 0d3d6fcce7
commit b309eecff9
7 changed files with 65 additions and 26 deletions

View File

@@ -43,7 +43,7 @@ NEXAccountSchema.method('generatePID', async function generatePID(): Promise<voi
const pid: number = Math.floor(Math.random() * (max - min + 1) + min);
const inuse: HydratedNEXAccountDocument = await NEXAccount.findOne({ pid });
const inuse: HydratedNEXAccountDocument | null = await NEXAccount.findOne({ pid });
if (inuse) {
await this.generatePID();

View File

@@ -83,16 +83,17 @@ class NintendoCertificate {
publicKeyData: Buffer;
constructor(certificate: string | Buffer) {
this._certificate = null;
this._certificateBody = null;
this.signatureType = null;
this.signature = null;
this.issuer = null;
this.keyType = null;
this.certificateName = null;
this.ngKeyId = null;
this.publicKey = null;
this.valid = null;
this._certificate = Buffer.alloc(0);
this._certificateBody = Buffer.alloc(0);
this.signatureType = 0;
this.signature = Buffer.alloc(0);
this.issuer = '';
this.keyType = 0;
this.certificateName = '';
this.ngKeyId = 0;
this.publicKey = Buffer.alloc(0);
this.valid = false;
this.publicKeyData = Buffer.alloc(0);
if (certificate) {
if (certificate instanceof Buffer) {

View File

@@ -32,8 +32,12 @@ function multipartParser(request: express.Request, response: express.Response, n
let fileName: string = '';
part.on('header', header => {
// TODO - strict mode yells here
fileName = RE_FILE_NAME.exec(header['content-disposition'][0])[1];
const contentDisposition = header['content-disposition' as keyof object];
const regexResult = RE_FILE_NAME.exec(contentDisposition);
if (regexResult) {
fileName = regexResult[0];
}
});
part.on('data', (data: Buffer | string) => {

View File

@@ -39,10 +39,10 @@ router.get('/mapped_ids', async (request: express.Request, response: express.Res
queryOutput = 'pid';
}
// This is slower than PNID.where()
// but it ensures that each input
// ALWAYS has an output and filters
// out unwanted input/output types
// * This is slower than PNID.where()
// * but it ensures that each input
// * ALWAYS has an output and filters
// * out unwanted input/output types
const results: {
in_id: string;
out_id: string;
@@ -64,8 +64,19 @@ router.get('/mapped_ids', async (request: express.Request, response: express.Res
pid?: number;
} = {};
// TODO - TS strict mode...what?
query[queryInput] = input;
if (queryInput === 'usernameLower') {
query.usernameLower = input;
}
if (queryInput === 'pid') {
query.pid = Number(input);
if (isNaN(query.pid)) {
// * Bail early
results.push(result);
continue;
}
}
const searchResult: HydratedPNIDDocument | null = await PNID.findOne(query);

View File

@@ -154,7 +154,7 @@ router.get('/time_zones/:countryCode/:language', (request: express.Request, resp
const countryCode: string = request.params.countryCode;
const language: string = request.params.language;
const regionLanguages: RegionLanguages = timezones[countryCode];
const regionLanguages: RegionLanguages = timezones[countryCode as keyof typeof timezones];
const regionTimezones: RegionTimezones = regionLanguages[language] ? regionLanguages[language] : Object.values(regionLanguages)[0];
response.send(xmlbuilder.create({

View File

@@ -56,7 +56,7 @@ router.get('/:username', async (request: express.Request, response: express.Resp
* Description: Registers a new NNID
*/
router.post('/', ratelimit, deviceCertificateMiddleware, async (request: express.Request, response: express.Response) => {
if (!request.certificate.valid) {
if (!request.certificate || !request.certificate.valid) {
// TODO: Change this to a different error
response.status(400);
@@ -118,9 +118,20 @@ router.post('/', ratelimit, deviceCertificateMiddleware, async (request: express
const language: string = person.get('language');
const timezoneName: string = person.get('tz_name');
const regionLanguages: RegionLanguages = timezones[countryCode];
const regionLanguages: RegionLanguages = timezones[countryCode as keyof typeof timezones];
const regionTimezones: RegionTimezones = regionLanguages[language] ? regionLanguages[language] : Object.values(regionLanguages)[0];
const timezone: RegionTimezone = regionTimezones.find(tz => tz.area === timezoneName);
let timezone: RegionTimezone | undefined = regionTimezones.find(tz => tz.area === timezoneName);
if (!timezone) {
// TODO - Change this, handle the error
timezone = {
area: 'America/New_York',
language: 'en',
name: 'Eastern Time (US &amp; Canada)',
order: '11',
utc_offset: '-14400'
};
}
pnid = new PNID({
pid: nexAccount.get('pid'),
@@ -475,9 +486,20 @@ router.put('/@me', async (request: express.Request, response: express.Response)
const marketingFlag: boolean = person.get('marketing_flag') ? person.get('marketing_flag') === 'Y' : pnid.get('flags.marketing');
const offDeviceFlag: boolean = person.get('off_device_flag') ? person.get('off_device_flag') === 'Y' : pnid.get('flags.off_device');
const regionLanguages: RegionLanguages = timezones[countryCode];
const regionLanguages: RegionLanguages = timezones[countryCode as keyof typeof timezones];
const regionTimezones: RegionTimezones = regionLanguages[language] ? regionLanguages[language] : Object.values(regionLanguages)[0];
const timezone: RegionTimezone = regionTimezones.find(tz => tz.area === timezoneName);
let timezone: RegionTimezone | undefined = regionTimezones.find(tz => tz.area === timezoneName);
if (!timezone) {
// TODO - Change this, handle the error
timezone = {
area: 'America/New_York',
language: 'en',
name: 'Eastern Time (US &amp; Canada)',
order: '11',
utc_offset: '-14400'
};
}
if (person.get('password')) {
const primaryPasswordHash: string = nintendoPasswordHash(person.get('password'), pnid.get('pid'));

View File

@@ -94,5 +94,6 @@ type Mii = {
creatorName: string;
checksum: number;
studioUrl: (options: MiiStudioURLOptions) => string
studioUrl: (options: MiiStudioURLOptions) => string;
encode: () => Buffer;
};