fix: decoding steamdb api key

This commit is contained in:
Hydra 2024-04-15 10:08:45 +01:00
parent ef035e46f8
commit cdd9908775
No known key found for this signature in database

View File

@ -14,21 +14,28 @@ export interface AlgoliaSearchParams {
} }
export const getSteamDBAlgoliaCredentials = async () => { export const getSteamDBAlgoliaCredentials = async () => {
const searchParams = new URLSearchParams({
t: new Date().getTime().toString(),
});
const js = await requestWebPage( const js = await requestWebPage(
"https://steamdb.info/static/js/instantsearch.js" `https://steamdb.info/static/js/instantsearch.js?${searchParams.toString()}`,
); );
const algoliaCredentialsRegExp = new RegExp( 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>( export const searchAlgolia = async <T>(
params: AlgoliaSearchParams params: AlgoliaSearchParams,
): Promise<AlgoliaResponse<T>> => { ): Promise<AlgoliaResponse<T>> => {
const algoliaCredentials = stateManager.getValue("steamDBAlgoliaCredentials"); const algoliaCredentials = stateManager.getValue("steamDBAlgoliaCredentials");
@ -48,7 +55,7 @@ export const searchAlgolia = async <T>(
}?${searchParams.toString()}`, }?${searchParams.toString()}`,
{ {
headers: params.headers, headers: params.headers,
} },
) )
.then((response) => response.data); .then((response) => response.data);
}; };