Skip to content

Commit

Permalink
Update how-long-to-beat extension (#15936)
Browse files Browse the repository at this point in the history
* Update how-long-to-beat extension

* Update CHANGELOG.md and optimise images

---------

Co-authored-by: raycastbot <[email protected]>
  • Loading branch information
ridemountainpig and raycastbot authored Dec 19, 2024
1 parent c6cf3f1 commit d9f0ae7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
4 changes: 4 additions & 0 deletions extensions/how-long-to-beat/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Howlongtobeat Changelog

## [Fixes] - 2024-12-19

- Fix: 404 error code again when fetching games by search

## [Fixes] - 2024-11-26

- Howlongtobeat updated dynamic search hash code
Expand Down
11 changes: 8 additions & 3 deletions extensions/how-long-to-beat/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ export const fetchLatestHash = async () => {

const text = response.data as string;

const keyRegex = /concat\("([a-zA-Z0-9]+)"\)/g;
const matches = [...text.matchAll(keyRegex)];
const hashParts = matches.map((match) => match[1]);
const apiFindRegex = /fetch\("\/api\/find\/"\s*\.concat\("([^"]+)"\)\s*\.concat\("([^"]+)"\)/;
const match = text.match(apiFindRegex);

let hashParts: string[] = [];
if (match) {
hashParts = [match[1], match[2]];
}

const hash = hashParts.join("");

if (hash) {
Expand Down
23 changes: 8 additions & 15 deletions extensions/how-long-to-beat/src/hltbsearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import { LocalStorage } from "@raycast/api";
export class HltbSearch {
public static BASE_URL = "https://howlongtobeat.com/";
public static DETAIL_URL = `${HltbSearch.BASE_URL}game?id=`;
public static SEARCH_URL = `${HltbSearch.BASE_URL}api/search/`;
public static SEARCH_URL = `${HltbSearch.BASE_URL}api/find/`;
public static IMAGE_URL = `${HltbSearch.BASE_URL}games/`;

payload: SearchPayload = {
searchType: "games",
searchTerms: [] as string[],
searchTerms: [""],
searchPage: 1,
size: 20,
searchOptions: {
Expand All @@ -24,20 +24,13 @@ export class HltbSearch {
platform: "",
sortCategory: "popular",
rangeCategory: "main",
rangeTime: {
min: 0,
max: 0,
},
gameplay: {
perspective: "",
flow: "",
genre: "",
},
rangeTime: { min: null, max: null },
gameplay: { perspective: "", flow: "", genre: "", difficulty: "" },
rangeYear: { min: "", max: "" },
modifier: "",
},
users: {
sortCategory: "postcount",
},
users: { sortCategory: "postcount" },
lists: { sortCategory: "follows" },
filter: "",
sort: 0,
randomizer: 0,
Expand All @@ -58,7 +51,7 @@ export class HltbSearch {
}

try {
const result = await ApiService.getInstance().post(`api/search/${localHash}`, search, {
const result = await ApiService.getInstance().post(`api/find/${localHash}`, search, {
timeout: 20000,
signal,
});
Expand Down
16 changes: 14 additions & 2 deletions extensions/how-long-to-beat/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
interface RangeTime {
min: number;
max: number;
min: null;
max: null;
}

interface RangeYear {
min: string;
max: string;
}

interface Gameplay {
perspective: string;
flow: string;
genre: string;
difficulty: string;
}

interface GamesOptions {
Expand All @@ -15,16 +21,22 @@ interface GamesOptions {
sortCategory: string;
rangeCategory: string;
rangeTime: RangeTime;
rangeYear: RangeYear;
gameplay: Gameplay;
modifier: string;
}

interface ListsOptions {
sortCategory: string;
}

interface UsersOptions {
sortCategory: string;
}

interface SearchOptions {
games: GamesOptions;
lists: ListsOptions;
users: UsersOptions;
filter: string;
sort: number;
Expand Down

0 comments on commit d9f0ae7

Please sign in to comment.