Skip to content
This repository has been archived by the owner on May 12, 2024. It is now read-only.

Commit

Permalink
improve logic for grabbing urls from epic games api
Browse files Browse the repository at this point in the history
  • Loading branch information
aloop committed Jan 18, 2024
1 parent 75a229e commit b775bf4
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion api-client/epic-games-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,29 @@ function getFormattedEndDate(game) {
return null;
}

function pickSlug(mapping) {
return mapping?.pageType?.toLowerCase?.() === "producthome";
}

function formatUrlFromSlug(slug) {
return slug ? new URL(slug, productBaseUrl).href : null;
}

function getUrl(game) {
if (game?.productSlug ?? false) {
return formatUrlFromSlug(game.productSlug);
} else if (
game?.catalogNs?.mappings?.length > 0 &&
Array.isArray(game.catalogNs.mappings)
) {
return formatUrlFromSlug(
game.catalogNs.mappings.find(pickSlug)?.pageSlug
);
}

return null;
}

function selectFreeGames(game) {
return (
// Check for a discounted price of $0
Expand All @@ -61,7 +84,7 @@ function formatGameData(game) {
title: game.title,
description: game.description,
id: game.id,
url: new URL(`${game?.productSlug}`, productBaseUrl).href,
url: getUrl(game),
thumbnailUrl:
game?.keyImages?.find(
(img) => img?.type?.toLowerCase() === "thumbnail"
Expand Down

0 comments on commit b775bf4

Please sign in to comment.