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 18, 2024
1 parent 6a35a6d commit 35e36d8
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions app/logic/stttools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@ import { Logger } from './logger';
const CLIENT_ID = '322613001274224';

export async function getSTTToken(username?: string, password?: string) {
Logger.info('Fetching new STT API token');
Logger.info('Fetching new STT API token');

const params = new URLSearchParams();
params.append('username', username ?? process.env.STT_BOT_USERNAME!);
params.append('password', password ?? process.env.STT_BOT_PASSWORD!);
params.append('grant_type', 'password');
params.append('client_id', CLIENT_ID);
const params = new URLSearchParams();

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());
params.append('username', username ?? process.env.STT_BOT_USERNAME!);
params.append('password', password ?? process.env.STT_BOT_PASSWORD!);
params.append('grant_type', 'password');
params.append('client_id', CLIENT_ID);

if (data?.access_token) {
Logger.info('New token fetched successfully');
return data.access_token as string;
} else {
Logger.info('Failed to fetch token', data);
throw new Error(`Failed to fetch token: ${data}`);
}
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 as string;
} else {
Logger.info('Failed to fetch token', data);
throw new Error(`Failed to fetch token: ${data}`);
}
}

0 comments on commit 35e36d8

Please sign in to comment.