Skip to content

Commit

Permalink
code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel Moschkin committed Nov 17, 2024
1 parent 90c3c0f commit 13ba53d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
19 changes: 10 additions & 9 deletions app/logic/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export class ApiResult {
}

export class ApiClass {
private _player_data: any;
private _stt_token: any;
private _player_data: { [index: string]: Date } = {};
private _stt_token: string = '';

private _cancelToken: NodeJS.Timeout | undefined = undefined;

Expand All @@ -50,11 +50,13 @@ export class ApiClass {

getSTTToken().then((token) => {
this._stt_token = token;
return token
})
.catch((e) => {
Logger.info("Using fallback token.");
this._stt_token = 'd6458837-34ba-4883-8588-4530f1a9cc53';
});
.then((token) => CelestialAPI.refreshCelestialMarket(token))
.catch((e) => {
Logger.info("Using fallback token.");
this._stt_token = 'd6458837-34ba-4883-8588-4530f1a9cc53';
});
}

async checkSTTResponse(res: Response) {
Expand Down Expand Up @@ -118,8 +120,7 @@ export class ApiClass {

try {
res = await uploadProfile(dbid, player_data, new Date());

this._player_data[dbid] = new Date().toUTCString();
this._player_data[dbid] = new Date();
fs.writeFileSync(`${process.env.PROFILE_DATA_PATH}/${dbid}`, JSON.stringify(player_data));

} catch (err) {
Expand Down Expand Up @@ -549,7 +550,7 @@ export class ApiClass {
}
}

this._player_data[dbid] = new Date().toUTCString();
this._player_data[dbid] = new Date();
fs.writeFileSync(`${process.env.PROFILE_DATA_PATH}/${dbid}`, JSON.stringify(player_data));

return {
Expand Down
4 changes: 2 additions & 2 deletions app/logic/stttools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ export async function getSTTToken(username?: string, password?: string) {
params.append('grant_type', 'password');
params.append('client_id', CLIENT_ID);

const data = await fetch(
const data = await fetch(
'https://thorium.disruptorbeam.com/oauth2/token',
{ method: 'POST', body: params, headers: { 'Content-type': 'application/x-www-form-urlencoded' } }
)
.then((res) => res.json());

if (data?.access_token) {
Logger.info('New token fetched successfully');
return data.access_token;
return data.access_token as string;
} else {
Logger.info('Failed to fetch token', data);
throw new Error(`Failed to fetch token: ${data}`);
Expand Down

0 comments on commit 13ba53d

Please sign in to comment.