Refactor and simplify start.gg import flow code

This commit is contained in:
Pandipipas
2026-02-16 01:28:50 +01:00
parent eda3f7b7b9
commit 6dcc2faf70
2 changed files with 10 additions and 19 deletions
+4 -6
View File
@@ -48,7 +48,6 @@ interface OAuthConfig {
interface OAuthSession {
sessionId: string;
state: string;
createdAt: number;
expiresAt: number;
status: 'pending' | 'completed' | 'error' | 'expired';
token?: string;
@@ -91,8 +90,9 @@ const requestStartGG = async <T>(query: string, variables: Record<string, unknow
return payload.data;
};
const countryByCode = new Set(getData().map((country: CountryRecord) => country.code.toUpperCase()));
const countryByName = new Map(getData().map((country: CountryRecord) => [country.name.toLowerCase(), country.code.toUpperCase()]));
const countries = getData();
const countryByCode = new Set(countries.map((country: CountryRecord) => country.code.toUpperCase()));
const countryByName = new Map(countries.map((country: CountryRecord) => [country.name.toLowerCase(), country.code.toUpperCase()]));
const resolveCountryCodeFromStartGG = (country: string | null | undefined): string => {
const raw = (country || '').trim();
@@ -346,12 +346,10 @@ nodecg.listenFor('startgg:createOAuthSession', async (_payload: unknown, ack) =>
const sessionId = randomUUID();
const state = randomUUID();
const now = Date.now();
const session: OAuthSession = {
sessionId,
state,
createdAt: now,
expiresAt: now + STARTGG_OAUTH_SESSION_TTL_MS,
expiresAt: Date.now() + STARTGG_OAUTH_SESSION_TTL_MS,
status: 'pending',
};
oauthSessions.set(sessionId, session);