mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-11-26 16:03:02 +00:00
upd: move totalSponsors and donationUrl check
This commit is contained in:
parent
34cbf55239
commit
6b459be117
1 changed files with 15 additions and 14 deletions
|
@ -33,9 +33,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
private metaService: MetaService,
|
private metaService: MetaService,
|
||||||
) {
|
) {
|
||||||
super(meta, paramDef, async (ps, me) => {
|
super(meta, paramDef, async (ps, me) => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
let totalSponsors: any;
|
|
||||||
|
|
||||||
const maybeCached = async (key: string, forcedUpdate: boolean, fetch_cb: () => void) => {
|
const maybeCached = async (key: string, forcedUpdate: boolean, fetch_cb: () => void) => {
|
||||||
// get Key first before doing the if statement as it can be defined as either string or null
|
// get Key first before doing the if statement as it can be defined as either string or null
|
||||||
const cached = await this.redisClient.get(key);
|
const cached = await this.redisClient.get(key);
|
||||||
|
@ -46,18 +43,20 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await fetch_cb();
|
const result = await fetch_cb();
|
||||||
await this.redisClient.set(key, JSON.stringify(totalSponsors), 'EX', 3600);
|
await this.redisClient.set(key, JSON.stringify(result), 'EX', 3600);
|
||||||
return result;
|
return result;
|
||||||
} catch (e) { return []; }
|
} catch (e) { return []; }
|
||||||
};
|
};
|
||||||
|
|
||||||
if (ps.instance) {
|
if (ps.instance) {
|
||||||
return { sponsor_data: await maybeCached('instanceSponsors', ps.forceUpdate, async () => {
|
return { sponsor_data: await maybeCached('instanceSponsors', ps.forceUpdate, async () => {
|
||||||
try {
|
let totalSponsors;
|
||||||
const meta = await this.metaService.fetch();
|
const meta = await this.metaService.fetch();
|
||||||
if (meta.donationUrl && !meta.donationUrl.includes('opencollective.com')) {
|
|
||||||
return [];
|
if (meta.donationUrl && !meta.donationUrl.includes('opencollective.com')) {
|
||||||
} else if (meta.donationUrl) {
|
return [];
|
||||||
|
} else if (meta.donationUrl) {
|
||||||
|
try {
|
||||||
const backers = await fetch(`${meta.donationUrl}/members/users.json`).then((response) => response.json());
|
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
|
// Merge both together into one array and make sure it only has Active subscriptions
|
||||||
|
@ -68,15 +67,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
|
|
||||||
await this.redisClient.set('instanceSponsors', JSON.stringify(totalSponsors), 'EX', 3600);
|
await this.redisClient.set('instanceSponsors', JSON.stringify(totalSponsors), 'EX', 3600);
|
||||||
return totalSponsors;
|
return totalSponsors;
|
||||||
} else {
|
} catch (error) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} else {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}) };
|
}) };
|
||||||
} else {
|
} else {
|
||||||
return { sponsor_data: await maybeCached('sponsors', ps.forceUpdate, async () => {
|
return { sponsor_data: await maybeCached('sponsors', ps.forceUpdate, async () => {
|
||||||
|
let totalSponsors;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const backers = await fetch('https://opencollective.com/sharkey/tiers/backer/all.json').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());
|
const sponsorsOC = await fetch('https://opencollective.com/sharkey/tiers/sponsor/all.json').then((response) => response.json());
|
||||||
|
|
Loading…
Reference in a new issue