fix: graphql JSON Parse Error (#3254)

This commit is contained in:
Zyx-A 2019-10-18 11:47:43 +08:00 committed by DIYgod
parent 9b7e6d35b7
commit 3015412b23
2 changed files with 45 additions and 28 deletions

View File

@ -546,4 +546,15 @@
},
],
},
'epicgames.com': {
_name: 'Epic Games',
www: [
{
title: '每周免费游戏',
docs: 'https://docs.rsshub.app/game.html#epicgames-freegame',
source: '/:collection',
target: '/epicgames/:collection',
},
],
},
});

View File

@ -1,3 +1,4 @@
const logger = require('@/utils/logger');
const got = require('@/utils/got');
const supportedList = require('./supportedList');
@ -32,35 +33,40 @@ module.exports = async (ctx) => {
const out = new Array();
let notHaveImageUrl = true;
data.Catalog.catalogOffers.elements.map((element) => {
if (element.promotions.promotionalOffers.length !== 0) {
element.promotions.promotionalOffers.forEach((isPromotionalOffer) => {
if (isPromotionalOffer.promotionalOffers.length !== 0) {
isPromotionalOffer.promotionalOffers.forEach((havePromotionalOffer) => {
if (havePromotionalOffer.discountSetting.discountType === 'PERCENTAGE' && havePromotionalOffer.discountSetting.discountPercentage === 0) {
item = {
title: element.title,
link: `https://www.epicgames.com/store/zh-CN/product/${element.productSlug}`,
pubDate: new Date(havePromotionalOffer.startDate).toUTCString(),
};
}
if (element.keyImages.length !== 0) {
element.keyImages.forEach((imageUrl) => {
if (imageUrl.type === 'DieselStoreFrontWide') {
item.description = `${element.description}<br><img src="${imageUrl.url}">`;
notHaveImageUrl = false;
}
});
}
if (notHaveImageUrl) {
item.description = element.description;
}
});
}
});
out.push(item);
item = {};
try {
if (element.promotions.promotionalOffers.length !== 0) {
element.promotions.promotionalOffers.forEach((isPromotionalOffer) => {
if (isPromotionalOffer.promotionalOffers.length !== 0) {
isPromotionalOffer.promotionalOffers.forEach((havePromotionalOffer) => {
if (havePromotionalOffer.discountSetting.discountType === 'PERCENTAGE' && havePromotionalOffer.discountSetting.discountPercentage === 0) {
item = {
title: element.title,
link: `https://www.epicgames.com/store/zh-CN/product/${element.productSlug}`,
pubDate: new Date(havePromotionalOffer.startDate).toUTCString(),
};
}
if (element.keyImages.length !== 0) {
element.keyImages.forEach((imageUrl) => {
if (imageUrl.type === 'DieselStoreFrontWide') {
item.description = `${element.description}<br><img src="${imageUrl.url}">`;
notHaveImageUrl = false;
}
});
}
if (notHaveImageUrl) {
item.description = element.description;
}
});
}
});
out.push(item);
item = {};
}
return true;
} catch (warn) {
logger.warn(element.title + '\t==> Parse Error Info:\n' + warn);
return false;
}
return true;
});
// out.pop(undefined);