From 9dd51bc9eb2cf8822b6286d9cd2f29c1cb8808a2 Mon Sep 17 00:00:00 2001 From: Marie Date: Wed, 2 Oct 2024 19:31:46 +0200 Subject: [PATCH] upd: fix donationUrl check position --- .../src/server/api/endpoints/sponsors.ts | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/sponsors.ts b/packages/backend/src/server/api/endpoints/sponsors.ts index 5557e478ee..dadc6eb819 100644 --- a/packages/backend/src/server/api/endpoints/sponsors.ts +++ b/packages/backend/src/server/api/endpoints/sponsors.ts @@ -49,31 +49,32 @@ export default class extends Endpoint { // eslint- }; if (ps.instance) { - return { sponsor_data: await maybeCached('instanceSponsors', ps.forceUpdate, async () => { - let totalSponsors; - const meta = await this.metaService.fetch(); - - if (meta.donationUrl && !meta.donationUrl.includes('opencollective.com')) { - return []; - } else if (meta.donationUrl) { + const meta = await this.metaService.fetch(); + if (meta.donationUrl && !meta.donationUrl.includes('opencollective.com')) { + return []; + } else if (meta.donationUrl) { + return { sponsor_data: await maybeCached('instanceSponsors', ps.forceUpdate, async () => { + let totalSponsors; + const meta = await this.metaService.fetch(); + try { const backers = await fetch(`${meta.donationUrl}/members/users.json`).then((response) => response.json()); - + // Merge both together into one array and make sure it only has Active subscriptions const allSponsors = [...backers].filter(sponsor => sponsor.isActive === true && sponsor.role === 'BACKER' && sponsor.tier); - + // Remove possible duplicates totalSponsors = [...new Map(allSponsors.map(v => [v.profile, v])).values()]; - + await this.redisClient.set('instanceSponsors', JSON.stringify(totalSponsors), 'EX', 3600); return totalSponsors; } catch (error) { return []; } - } else { - return []; - } - }) }; + }) }; + } else { + return []; + } } else { return { sponsor_data: await maybeCached('sponsors', ps.forceUpdate, async () => { let totalSponsors;