@@ -7,20 +7,18 @@ import { Server } from '@/models/server';
7
7
import { LOG_ERROR } from '@/logger' ;
8
8
import { config } from '@/config-manager' ;
9
9
import { HydratedPNIDDocument } from '@/types/mongoose/pnid' ;
10
- import { IDevice } from '@/types/mongoose/device' ;
11
10
import { IDeviceAttribute } from '@/types/mongoose/device-attribute' ;
12
11
import { HydratedServerDocument } from '@/types/mongoose/server' ;
13
- import { Token } from '@/types/common/token' ;
14
12
import { PNIDProfile } from '@/types/services/nnas/pnid-profile' ;
15
13
import { ConnectionData } from '@/types/services/api/connection-data' ;
16
14
import { ConnectionResponse } from '@/types/services/api/connection-response' ;
17
15
import { DiscordConnectionData } from '@/types/services/api/discord-connection-data' ;
18
16
19
- const connection_string : string = config . mongoose . connection_string ;
20
- const options : mongoose . ConnectOptions = config . mongoose . options ;
17
+ const connection_string = config . mongoose . connection_string ;
18
+ const options = config . mongoose . options ;
21
19
22
20
// TODO: Extend this later with more settings
23
- const discordConnectionSchema : joi . ObjectSchema = joi . object ( {
21
+ const discordConnectionSchema = joi . object ( {
24
22
id : joi . string ( )
25
23
} ) ;
26
24
@@ -79,19 +77,19 @@ export async function getPNIDByBasicAuth(token: string): Promise<HydratedPNIDDoc
79
77
80
78
// * Wii U sends Basic auth as `username password`, where the password may not have spaces
81
79
// * This is not to spec, but that is the consoles fault not ours
82
- const decoded : string = Buffer . from ( token , 'base64' ) . toString ( ) ;
83
- const parts : string [ ] = decoded . split ( ' ' ) ;
80
+ const decoded = Buffer . from ( token , 'base64' ) . toString ( ) ;
81
+ const parts = decoded . split ( ' ' ) ;
84
82
85
- const username : string = parts [ 0 ] ;
86
- const password : string = parts [ 1 ] ;
83
+ const username = parts [ 0 ] ;
84
+ const password = parts [ 1 ] ;
87
85
88
- const pnid : HydratedPNIDDocument | null = await getPNIDByUsername ( username ) ;
86
+ const pnid = await getPNIDByUsername ( username ) ;
89
87
90
88
if ( ! pnid ) {
91
89
return null ;
92
90
}
93
91
94
- const hashedPassword : string = nintendoPasswordHash ( password , pnid . pid ) ;
92
+ const hashedPassword = nintendoPasswordHash ( password , pnid . pid ) ;
95
93
96
94
if ( ! bcrypt . compareSync ( hashedPassword , pnid . password ) ) {
97
95
return null ;
@@ -104,13 +102,12 @@ export async function getPNIDByTokenAuth(token: string): Promise<HydratedPNIDDoc
104
102
verifyConnected ( ) ;
105
103
106
104
try {
107
- const decryptedToken : Buffer = decryptToken ( Buffer . from ( token , 'hex' ) ) ;
108
- const unpackedToken : Token = unpackToken ( decryptedToken ) ;
109
-
110
- const pnid : HydratedPNIDDocument | null = await getPNIDByPID ( unpackedToken . pid ) ;
105
+ const decryptedToken = decryptToken ( Buffer . from ( token , 'hex' ) ) ;
106
+ const unpackedToken = unpackToken ( decryptedToken ) ;
107
+ const pnid = await getPNIDByPID ( unpackedToken . pid ) ;
111
108
112
109
if ( pnid ) {
113
- const expireTime : number = Math . floor ( ( Number ( unpackedToken . expire_time ) / 1000 ) ) ;
110
+ const expireTime = Math . floor ( ( Number ( unpackedToken . expire_time ) / 1000 ) ) ;
114
111
115
112
if ( Math . floor ( Date . now ( ) / 1000 ) > expireTime ) {
116
113
return null ;
@@ -128,13 +125,13 @@ export async function getPNIDByTokenAuth(token: string): Promise<HydratedPNIDDoc
128
125
export async function getPNIDProfileJSONByPID ( pid : number ) : Promise < PNIDProfile | null > {
129
126
verifyConnected ( ) ;
130
127
131
- const pnid : HydratedPNIDDocument | null = await getPNIDByPID ( pid ) ;
128
+ const pnid = await getPNIDByPID ( pid ) ;
132
129
133
130
if ( ! pnid ) {
134
131
return null ;
135
132
}
136
133
137
- const device : IDevice = pnid . devices [ 0 ] ; // * Just grab the first device
134
+ const device = pnid . devices [ 0 ] ; // * Just grab the first device
138
135
let device_attributes : {
139
136
device_attribute : {
140
137
name : string ;
@@ -145,9 +142,9 @@ export async function getPNIDProfileJSONByPID(pid: number): Promise<PNIDProfile
145
142
146
143
if ( device ) {
147
144
device_attributes = device . device_attributes . map ( ( attribute : IDeviceAttribute ) => {
148
- const name : string = attribute . name ;
149
- const value : string = attribute . value ;
150
- const created_date : string | undefined = attribute . created_date ;
145
+ const name = attribute . name ;
146
+ const value = attribute . value ;
147
+ const created_date = attribute . created_date ;
151
148
152
149
return {
153
150
device_attribute : {
@@ -237,7 +234,7 @@ export async function addPNIDConnection(pnid: HydratedPNIDDocument, data: Connec
237
234
}
238
235
239
236
export async function addPNIDConnectionDiscord ( pnid : HydratedPNIDDocument , data : DiscordConnectionData ) : Promise < ConnectionResponse > {
240
- const valid : joi . ValidationResult = discordConnectionSchema . validate ( data ) ;
237
+ const valid = discordConnectionSchema . validate ( data ) ;
241
238
242
239
if ( valid . error ) {
243
240
return {
0 commit comments