Skip to content

Commit

Permalink
fix: decoding steamdb api key
Browse files Browse the repository at this point in the history
  • Loading branch information
thegrannychaseroperation committed Apr 15, 2024
1 parent ef035e4 commit cdd9908
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/main/services/algolia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,28 @@ export interface AlgoliaSearchParams {
}

export const getSteamDBAlgoliaCredentials = async () => {
const searchParams = new URLSearchParams({
t: new Date().getTime().toString(),
});

const js = await requestWebPage(
"https://steamdb.info/static/js/instantsearch.js"
`https://steamdb.info/static/js/instantsearch.js?${searchParams.toString()}`,
);

const algoliaCredentialsRegExp = new RegExp(
/algoliasearch\("(.*?)","(.*?)"\);/
/algoliasearch\("(.*?)",atob\("(.*?)"\)\);/,
);

const [, applicationId, apiKey] = algoliaCredentialsRegExp.exec(js);
const [, applicationId, encodedApiKey] = algoliaCredentialsRegExp.exec(js);

return { applicationId, apiKey };
return {
applicationId,
apiKey: Buffer.from(encodedApiKey, "base64").toString("utf-8"),
};
};

export const searchAlgolia = async <T>(
params: AlgoliaSearchParams
params: AlgoliaSearchParams,
): Promise<AlgoliaResponse<T>> => {
const algoliaCredentials = stateManager.getValue("steamDBAlgoliaCredentials");

Expand All @@ -48,7 +55,7 @@ export const searchAlgolia = async <T>(
}?${searchParams.toString()}`,
{
headers: params.headers,
}
},
)
.then((response) => response.data);
};

0 comments on commit cdd9908

Please sign in to comment.