add: sponsors
This commit is contained in:
parent
96d99f04fb
commit
2d31c189d8
|
@ -354,6 +354,7 @@ import * as ep___users_achievements from './endpoints/users/achievements.js';
|
|||
import * as ep___users_updateMemo from './endpoints/users/update-memo.js';
|
||||
import * as ep___fetchRss from './endpoints/fetch-rss.js';
|
||||
import * as ep___retention from './endpoints/retention.js';
|
||||
import * as ep___sponsors from './endpoints/sponsors.js';
|
||||
import { GetterService } from './GetterService.js';
|
||||
import { ApiLoggerService } from './ApiLoggerService.js';
|
||||
import type { Provider } from '@nestjs/common';
|
||||
|
@ -706,6 +707,7 @@ const $users_achievements: Provider = { provide: 'ep:users/achievements', useCla
|
|||
const $users_updateMemo: Provider = { provide: 'ep:users/update-memo', useClass: ep___users_updateMemo.default };
|
||||
const $fetchRss: Provider = { provide: 'ep:fetch-rss', useClass: ep___fetchRss.default };
|
||||
const $retention: Provider = { provide: 'ep:retention', useClass: ep___retention.default };
|
||||
const $sponsors: Provider = { provide: 'ep:sponsors', useClass: ep___sponsors.default };
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
@ -1062,6 +1064,7 @@ const $retention: Provider = { provide: 'ep:retention', useClass: ep___retention
|
|||
$users_updateMemo,
|
||||
$fetchRss,
|
||||
$retention,
|
||||
$sponsors,
|
||||
],
|
||||
exports: [
|
||||
$admin_meta,
|
||||
|
@ -1409,6 +1412,7 @@ const $retention: Provider = { provide: 'ep:retention', useClass: ep___retention
|
|||
$users_updateMemo,
|
||||
$fetchRss,
|
||||
$retention,
|
||||
$sponsors,
|
||||
],
|
||||
})
|
||||
export class EndpointsModule {}
|
||||
|
|
|
@ -354,6 +354,7 @@ import * as ep___users_achievements from './endpoints/users/achievements.js';
|
|||
import * as ep___users_updateMemo from './endpoints/users/update-memo.js';
|
||||
import * as ep___fetchRss from './endpoints/fetch-rss.js';
|
||||
import * as ep___retention from './endpoints/retention.js';
|
||||
import * as ep___sponsors from './endpoints/sponsors.js';
|
||||
|
||||
const eps = [
|
||||
['admin/meta', ep___admin_meta],
|
||||
|
@ -704,6 +705,7 @@ const eps = [
|
|||
['users/update-memo', ep___users_updateMemo],
|
||||
['fetch-rss', ep___fetchRss],
|
||||
['retention', ep___retention],
|
||||
['sponsors', ep___sponsors],
|
||||
];
|
||||
|
||||
export interface IEndpointMeta {
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import * as Redis from 'ioredis';
|
||||
|
||||
export const meta = {
|
||||
tags: ["meta"],
|
||||
description: "Get Sharkey GH Sponsors",
|
||||
|
||||
requireCredential: false,
|
||||
requireCredentialPrivateMode: false,
|
||||
} as const;
|
||||
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
forceUpdate: { type: "boolean", default: false },
|
||||
},
|
||||
required: [],
|
||||
} as const;
|
||||
|
||||
@Injectable()
|
||||
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
||||
constructor(
|
||||
@Inject(DI.redis) private redisClient: Redis.Redis,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
let sponsors;
|
||||
const cachedSponsors = await this.redisClient.get("sponsors");
|
||||
if (!ps.forceUpdate && cachedSponsors) {
|
||||
sponsors = JSON.parse(cachedSponsors);
|
||||
} else {
|
||||
AbortSignal.timeout ??= function timeout(ms) {
|
||||
const ctrl = new AbortController();
|
||||
setTimeout(() => ctrl.abort(), ms);
|
||||
return ctrl.signal;
|
||||
};
|
||||
|
||||
sponsors = await fetch("https://kaifa.ch/transfem-sponsors.json",{ signal: AbortSignal.timeout(2000) })
|
||||
.then((response) => response.json());
|
||||
await this.redisClient.set("sponsors", JSON.stringify(sponsors), "EX", 3600);
|
||||
}
|
||||
return { sponsor_data: sponsors['sponsors'] };
|
||||
})
|
||||
}
|
||||
}
|
|
@ -84,6 +84,21 @@ SPDX-License-Identifier: AGPL-3.0-only
|
|||
</a>
|
||||
</div>
|
||||
</FormSection>
|
||||
<FormSection>
|
||||
<template #label>Our lovely GitHub Sponsors</template>
|
||||
<div :class="$style.contributors">
|
||||
<span
|
||||
v-for="sponsor in sponsors[0]"
|
||||
:key="sponsor"
|
||||
style="margin-bottom: 0.5rem;"
|
||||
>
|
||||
<a :href="sponsor.profile" target="_blank" :class="$style.contributor">
|
||||
<img :src="sponsor.avatar" :class="$style.contributorAvatar">
|
||||
<span :class="$style.contributorUsername">{{ sponsor.details.name }}</span>
|
||||
</a>
|
||||
</span>
|
||||
</div>
|
||||
</FormSection>
|
||||
</div>
|
||||
</MkSpacer>
|
||||
</div>
|
||||
|
@ -110,8 +125,11 @@ let thereIsTreasure = $ref($i && !claimedAchievements.includes('foundTreasure'))
|
|||
let easterEggReady = false;
|
||||
let easterEggEmojis = $ref([]);
|
||||
let easterEggEngine = $ref(null);
|
||||
let sponsors = $ref([]);
|
||||
const containerEl = $shallowRef<HTMLElement>();
|
||||
|
||||
await os.api('sponsors', { forceUpdate: true }).then((res) => sponsors.push(res.sponsor_data));
|
||||
|
||||
function iconLoaded() {
|
||||
const emojis = defaultStore.state.reactions;
|
||||
const containerWidth = containerEl.offsetWidth;
|
||||
|
|
|
@ -583,6 +583,9 @@ export type Endpoints = {
|
|||
// reset-password
|
||||
'reset-password': { req: { token: string; password: string; }; res: null; };
|
||||
|
||||
// sponsors
|
||||
'sponsors': { req: { forceUpdate: boolean; }; res: null; };
|
||||
|
||||
// room
|
||||
'room/show': { req: TODO; res: TODO; };
|
||||
'room/update': { req: TODO; res: TODO; };
|
||||
|
|
Loading…
Reference in New Issue