Skip to content

Commit

Permalink
Fix the HLTB API "obfuscation" (#108)
Browse files Browse the repository at this point in the history
* `hltb` adjust for new API "obfuscation"
* use a browser user agent
  • Loading branch information
Supinic authored Nov 16, 2024
1 parent e023815 commit 1494ba4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions commands/howlongtobeat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const HLTB_ENDPOINT_HASH_KEY = "hltb-endpoint-hash";

const FILE_PREFIX = "_next/static/chunks/pages";
const FILE_HASH_REGEX = /static\/chunks\/pages\/(_app-\w+?\.js)/;
const ENDPOINT_HASH_REGEX = /\/api\/search\/".concat\("(\w+)"\)/;
const ENDPOINT_HASH_REGEX = /\/api\/search\/".concat\("(\w+)"\)\s*(.concat\("(\w+)"\))?/;

const fetchFileHash = async (force = false) => {
const existing = await sb.Cache.getByPrefix(HLTB_JS_FILE_HASH_KEY);
Expand Down Expand Up @@ -59,7 +59,7 @@ const fetchEndpointHash = async (fileHash, force = false) => {
expiry: 864e5 // 1 day
});

return match[1];
return (match[3]) ? `${match[1]}${match[3]}` : match[1];
};

module.exports = {
Expand Down Expand Up @@ -95,7 +95,7 @@ module.exports = {
};
}

const response = await sb.Got.get("GenericAPI")({
const response = await sb.Got.get("FakeAgent")({
url: `https://howlongtobeat.com/api/search/${endpointHash}`,
method: "POST",
throwHttpErrors: false,
Expand Down

0 comments on commit 1494ba4

Please sign in to comment.