mirror of
https://github.com/PretendoNetwork/account.git
synced 2026-09-12 21:38:12 -05:00
fix: don't use the in operator for checking in an array
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import express from 'express';
|
||||
import xmlbuilder from 'xmlbuilder';
|
||||
import { getServerByClientID, getServerByGameServerID } from '@/database';
|
||||
import { generateToken, getValueFromHeaders, getValueFromQueryString } from '@/util';
|
||||
import { generateToken, getValueFromHeaders, getValueFromQueryString, isSystemType } from '@/util';
|
||||
import { NEXAccount } from '@/models/nex-account';
|
||||
import { SystemType, TokenOptions, TokenType } from '@/types/common/token';
|
||||
|
||||
@@ -90,7 +90,7 @@ router.get('/service_token/@me', async (request: express.Request, response: expr
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(server.device in Object.values(SystemType))) {
|
||||
if (!isSystemType(server.device)) {
|
||||
throw new Error('Invalid system type');
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ router.get('/nex_token/@me', async (request: express.Request, response: express.
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(server.device in Object.values(SystemType))) {
|
||||
if (!isSystemType(server.device)) {
|
||||
throw new Error('Invalid system type');
|
||||
}
|
||||
|
||||
|
||||
16
src/util.ts
16
src/util.ts
@@ -85,6 +85,14 @@ export function generateOAuthTokens(systemType: SystemType, pnid: HydratedPNIDDo
|
||||
};
|
||||
}
|
||||
|
||||
export function isSystemType(value: number): value is SystemType {
|
||||
return (Object.values(SystemType) as number[]).includes(value);
|
||||
}
|
||||
|
||||
export function isTokenType(value: number): value is TokenType {
|
||||
return (Object.values(TokenType) as number[]).includes(value);
|
||||
}
|
||||
|
||||
|
||||
export function generateToken(key: string, options: TokenOptions): Buffer {
|
||||
let dataBuffer = Buffer.alloc(1 + 1 + 4 + 8);
|
||||
@@ -165,12 +173,12 @@ export function unpackToken(token: Buffer): Token {
|
||||
const systemType = token.readUInt8(0x0);
|
||||
const tokenType = token.readUInt8(0x1);
|
||||
|
||||
if (!(systemType in Object.values(SystemType))) throw new Error('Invalid system type');
|
||||
if (!(tokenType in Object.values(TokenType))) throw new Error('Invalid token type');
|
||||
if (!isSystemType(systemType)) throw new Error('Invalid system type');
|
||||
if (!isTokenType(tokenType)) throw new Error('Invalid token type');
|
||||
|
||||
const unpacked: Token = {
|
||||
system_type: systemType as SystemType,
|
||||
token_type: tokenType as TokenType,
|
||||
system_type: systemType,
|
||||
token_type: tokenType,
|
||||
pid: token.readUInt32LE(0x2),
|
||||
expire_time: token.readBigUInt64LE(0x6)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user