From b7815df1343a5858dfe7037acfabf5e962516e17 Mon Sep 17 00:00:00 2001 From: Marie Date: Sun, 15 Sep 2024 20:04:29 +0200 Subject: [PATCH] upd: fetch sponsors from OC --- .../src/server/api/endpoints/sponsors.ts | 33 +++++++++---------- packages/frontend/src/pages/about-sharkey.vue | 8 ++--- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/sponsors.ts b/packages/backend/src/server/api/endpoints/sponsors.ts index b6ccb9b2f9..67712ca379 100644 --- a/packages/backend/src/server/api/endpoints/sponsors.ts +++ b/packages/backend/src/server/api/endpoints/sponsors.ts @@ -10,7 +10,7 @@ import { DI } from '@/di-symbols.js'; export const meta = { tags: ['meta'], - description: 'Get Sharkey GH Sponsors', + description: 'Get Sharkey Sponsors', requireCredential: false, requireCredentialPrivateMode: false, @@ -30,29 +30,28 @@ export default class extends Endpoint { // eslint- @Inject(DI.redis) private redisClient: Redis.Redis, ) { super(meta, paramDef, async (ps, me) => { - let sponsors; - const cachedSponsors = await this.redisClient.get('sponsors'); + let totalSponsors; + const cachedSponsors = await this.redisClient.get('sponsors'); + if (!ps.forceUpdate && cachedSponsors) { - sponsors = JSON.parse(cachedSponsors); + totalSponsors = JSON.parse(cachedSponsors); } else { - AbortSignal.timeout ??= function timeout(ms) { - const ctrl = new AbortController(); - setTimeout(() => ctrl.abort(), ms); - return ctrl.signal; - }; - try { - sponsors = await fetch('https://kaifa.ch/transfem-sponsors.json', { signal: AbortSignal.timeout(2000) }) - .then((response) => response.json()); + const backers = await fetch('https://opencollective.com/sharkey/tiers/backer/all.json').then((response) => response.json()); + const sponsorsOC = await fetch('https://opencollective.com/sharkey/tiers/sponsor/all.json').then((response) => response.json()); - await this.redisClient.set('sponsors', JSON.stringify(sponsors), 'EX', 3600); + // Merge both together into one array and make sure it only has Active subscriptions + const allSponsors = [...backers, ...sponsorsOC].filter(sponsor => sponsor.isActive == true); + + // Remove possible duplicates + totalSponsors = [...new Map(allSponsors.map(v => [v.profile, v])).values()]; + + await this.redisClient.set('sponsors', JSON.stringify(totalSponsors), 'EX', 3600); } catch (error) { - sponsors = { - sponsors: [], - }; + totalSponsors = []; } } - return { sponsor_data: sponsors['sponsors'] }; + return { sponsor_data: totalSponsors }; }); } } diff --git a/packages/frontend/src/pages/about-sharkey.vue b/packages/frontend/src/pages/about-sharkey.vue index 2d1a3111c2..938786949c 100644 --- a/packages/frontend/src/pages/about-sharkey.vue +++ b/packages/frontend/src/pages/about-sharkey.vue @@ -170,9 +170,9 @@ SPDX-License-Identifier: AGPL-3.0-only :key="sponsor" style="margin-bottom: 0.5rem;" > - - - {{ sponsor.details.name }} + + + {{ sponsor.name }} @@ -209,7 +209,7 @@ const easterEggEngine = ref(null); const sponsors = ref([]); const containerEl = shallowRef(); -await misskeyApi('sponsors', { forceUpdate: true }).then((res) => sponsors.value.push(res.sponsor_data)); +await misskeyApi('sponsors', { forceUpdate: false }).then((res) => sponsors.value.push(res.sponsor_data)); function iconLoaded() { const emojis = defaultStore.state.reactions;