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
This commit is contained in:
KotaHv
2022-05-27 16:37:50 +08:00
committed by GitHub
parent 83aca709b0
commit d719977c30
+32 -7
View File
@@ -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),
};
};