merge: Fetch sponsors from OC (!624)

View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/624

Closes #653

Approved-by: Julia <julia@insertdomain.name>
Approved-by: Tess K <me@thvxl.se>
This commit is contained in:
dakkar 2024-09-23 17:57:39 +00:00
commit 69efba9366
2 changed files with 20 additions and 21 deletions

View file

@ -10,7 +10,7 @@ import { DI } from '@/di-symbols.js';
export const meta = { export const meta = {
tags: ['meta'], tags: ['meta'],
description: 'Get Sharkey GH Sponsors', description: 'Get Sharkey Sponsors',
requireCredential: false, requireCredential: false,
requireCredentialPrivateMode: false, requireCredentialPrivateMode: false,
@ -30,29 +30,28 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
@Inject(DI.redis) private redisClient: Redis.Redis, @Inject(DI.redis) private redisClient: Redis.Redis,
) { ) {
super(meta, paramDef, async (ps, me) => { super(meta, paramDef, async (ps, me) => {
let sponsors; let totalSponsors;
const cachedSponsors = await this.redisClient.get('sponsors'); const cachedSponsors = await this.redisClient.get('sponsors');
if (!ps.forceUpdate && cachedSponsors) { if (!ps.forceUpdate && cachedSponsors) {
sponsors = JSON.parse(cachedSponsors); totalSponsors = JSON.parse(cachedSponsors);
} else { } else {
AbortSignal.timeout ??= function timeout(ms) {
const ctrl = new AbortController();
setTimeout(() => ctrl.abort(), ms);
return ctrl.signal;
};
try { try {
sponsors = await fetch('https://kaifa.ch/transfem-sponsors.json', { signal: AbortSignal.timeout(2000) }) const backers = await fetch('https://opencollective.com/sharkey/tiers/backer/all.json').then((response) => response.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 = [...sponsorsOC, ...backers].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) { } catch (error) {
sponsors = { totalSponsors = [];
sponsors: [],
};
} }
} }
return { sponsor_data: sponsors['sponsors'] }; return { sponsor_data: totalSponsors };
}); });
} }
} }

View file

@ -170,9 +170,9 @@ SPDX-License-Identifier: AGPL-3.0-only
:key="sponsor" :key="sponsor"
style="margin-bottom: 0.5rem;" style="margin-bottom: 0.5rem;"
> >
<a :href="sponsor.profile" target="_blank" :class="$style.contributor"> <a :href="sponsor.website || sponsor.profile" target="_blank" :class="$style.contributor">
<img :src="sponsor.avatar" :class="$style.contributorAvatar"> <img :src="sponsor.image || `https://ui-avatars.com/api/?background=0D8ABC&color=fff&name=${sponsor.name}`" :class="$style.contributorAvatar">
<span :class="$style.contributorUsername">{{ sponsor.details.name }}</span> <span :class="$style.contributorUsername">{{ sponsor.name }}</span>
</a> </a>
</span> </span>
</div> </div>
@ -209,7 +209,7 @@ const easterEggEngine = ref(null);
const sponsors = ref([]); const sponsors = ref([]);
const containerEl = shallowRef<HTMLElement>(); const containerEl = shallowRef<HTMLElement>();
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() { function iconLoaded() {
const emojis = defaultStore.state.reactions; const emojis = defaultStore.state.reactions;