From d719977c30b4af13152d80b0e1c0ec0c241e2c73 Mon Sep 17 00:00:00 2001 From: KotaHv <92137267+KotaHv@users.noreply.github.com> Date: Fri, 27 May 2022 16:37:50 +0800 Subject: [PATCH] fix(route): Epic Games Store (#9836) * fix(route): Epic Games Store * modify categories.forEach to categories.some * fix(route): Epic Games Store - fix item image url * fix(route): Epic Games Store - fix item description --- lib/v2/epicgames/index.js | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/lib/v2/epicgames/index.js b/lib/v2/epicgames/index.js index 6d746a0c73..2777c11e2e 100644 --- a/lib/v2/epicgames/index.js +++ b/lib/v2/epicgames/index.js @@ -11,6 +11,7 @@ module.exports = async (ctx) => { const rootUrl = 'https://store.epicgames.com'; const currentUrl = `${rootUrl}/${locale}/free-games?lang=${locale}`; const apiUrl = `https://store-site-backend-static-ipv4.ak.epicgames.com/freeGamesPromotions?locale=${locale}&country=${country}&allowCountries=${country}`; + const contentBaseUrl = `https://store-content-ipv4.ak.epicgames.com/api/${locale}/content`; const response = await got({ method: 'get', @@ -27,29 +28,53 @@ module.exports = async (ctx) => { dayjs(item.promotions.promotionalOffers[0].promotionalOffers[0].startDate) <= now && dayjs(item.promotions.promotionalOffers[0].promotionalOffers[0].endDate) > now ) - .map((item) => { + .map(async (item) => { let link = `${rootUrl}/${locale}/p/`; - item.categories.forEach((category) => { + let contentUrl = `${contentBaseUrl}/products/`; + let isBundles = false; + item.categories.some((category) => { if (category.path === 'bundles') { link = `${rootUrl}/${locale}/bundles/`; + isBundles = true; + contentUrl = `${contentBaseUrl}/bundles/`; + return true; } + return false; + }); + const linkSlug = item.catalogNs.mappings.length > 0 ? item.catalogNs.mappings[0].pageSlug : item.offerMappings.length > 0 ? item.offerMappings[0].pageSlug : item.productSlug ? item.productSlug : item.urlSlug; + link += linkSlug; + contentUrl += linkSlug; + let description = item.description; + if (item.offerType !== 'BASE_GAME') { + const contentResp = await got({ + method: 'get', + url: contentUrl, + }); + description = isBundles ? contentResp.data.data.about.shortDescription : contentResp.data.pages[0].data.about.shortDescription; + } + + let image = item.keyImages[0].url; + item.keyImages.some((keyImage) => { + if (keyImage.type === 'DieselStoreFrontWide') { + image = keyImage.url; + return true; + } + return false; }); - link += item.catalogNs.mappings.length > 0 ? item.catalogNs.mappings[0].pageSlug : item.offerMappings.length > 0 ? item.offerMappings[0].pageSlug : item.productSlug ? item.productSlug : item.urlSlug; return { title: item.title, author: item.seller.name, link, description: art(path.join(__dirname, 'templates/description.art'), { - description: item.description, - image: item.keyImages[0].url, + description, + image, }), pubDate: parseDate(item.promotions.promotionalOffers[0].promotionalOffers[0].startDate), }; }); - ctx.state.data = { title: 'Epic Games Store - Free Games', link: currentUrl, - item: items, + item: await Promise.all(items), }; };