add: sponsors

This commit is contained in:
Mar0xy 2023-10-14 01:59:09 +02:00
parent 96d99f04fb
commit 2d31c189d8
No known key found for this signature in database
GPG Key ID: 56569BBE47D2C828
5 changed files with 73 additions and 0 deletions

View File

@ -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___users_updateMemo from './endpoints/users/update-memo.js';
import * as ep___fetchRss from './endpoints/fetch-rss.js'; import * as ep___fetchRss from './endpoints/fetch-rss.js';
import * as ep___retention from './endpoints/retention.js'; import * as ep___retention from './endpoints/retention.js';
import * as ep___sponsors from './endpoints/sponsors.js';
import { GetterService } from './GetterService.js'; import { GetterService } from './GetterService.js';
import { ApiLoggerService } from './ApiLoggerService.js'; import { ApiLoggerService } from './ApiLoggerService.js';
import type { Provider } from '@nestjs/common'; 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 $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 $fetchRss: Provider = { provide: 'ep:fetch-rss', useClass: ep___fetchRss.default };
const $retention: Provider = { provide: 'ep:retention', useClass: ep___retention.default }; const $retention: Provider = { provide: 'ep:retention', useClass: ep___retention.default };
const $sponsors: Provider = { provide: 'ep:sponsors', useClass: ep___sponsors.default };
@Module({ @Module({
imports: [ imports: [
@ -1062,6 +1064,7 @@ const $retention: Provider = { provide: 'ep:retention', useClass: ep___retention
$users_updateMemo, $users_updateMemo,
$fetchRss, $fetchRss,
$retention, $retention,
$sponsors,
], ],
exports: [ exports: [
$admin_meta, $admin_meta,
@ -1409,6 +1412,7 @@ const $retention: Provider = { provide: 'ep:retention', useClass: ep___retention
$users_updateMemo, $users_updateMemo,
$fetchRss, $fetchRss,
$retention, $retention,
$sponsors,
], ],
}) })
export class EndpointsModule {} export class EndpointsModule {}

View File

@ -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___users_updateMemo from './endpoints/users/update-memo.js';
import * as ep___fetchRss from './endpoints/fetch-rss.js'; import * as ep___fetchRss from './endpoints/fetch-rss.js';
import * as ep___retention from './endpoints/retention.js'; import * as ep___retention from './endpoints/retention.js';
import * as ep___sponsors from './endpoints/sponsors.js';
const eps = [ const eps = [
['admin/meta', ep___admin_meta], ['admin/meta', ep___admin_meta],
@ -704,6 +705,7 @@ const eps = [
['users/update-memo', ep___users_updateMemo], ['users/update-memo', ep___users_updateMemo],
['fetch-rss', ep___fetchRss], ['fetch-rss', ep___fetchRss],
['retention', ep___retention], ['retention', ep___retention],
['sponsors', ep___sponsors],
]; ];
export interface IEndpointMeta { export interface IEndpointMeta {

View File

@ -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'] };
})
}
}

View File

@ -84,6 +84,21 @@ SPDX-License-Identifier: AGPL-3.0-only
</a> </a>
</div> </div>
</FormSection> </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> </div>
</MkSpacer> </MkSpacer>
</div> </div>
@ -110,8 +125,11 @@ let thereIsTreasure = $ref($i && !claimedAchievements.includes('foundTreasure'))
let easterEggReady = false; let easterEggReady = false;
let easterEggEmojis = $ref([]); let easterEggEmojis = $ref([]);
let easterEggEngine = $ref(null); let easterEggEngine = $ref(null);
let sponsors = $ref([]);
const containerEl = $shallowRef<HTMLElement>(); const containerEl = $shallowRef<HTMLElement>();
await os.api('sponsors', { forceUpdate: true }).then((res) => sponsors.push(res.sponsor_data));
function iconLoaded() { function iconLoaded() {
const emojis = defaultStore.state.reactions; const emojis = defaultStore.state.reactions;
const containerWidth = containerEl.offsetWidth; const containerWidth = containerEl.offsetWidth;

View File

@ -583,6 +583,9 @@ export type Endpoints = {
// reset-password // reset-password
'reset-password': { req: { token: string; password: string; }; res: null; }; 'reset-password': { req: { token: string; password: string; }; res: null; };
// sponsors
'sponsors': { req: { forceUpdate: boolean; }; res: null; };
// room // room
'room/show': { req: TODO; res: TODO; }; 'room/show': { req: TODO; res: TODO; };
'room/update': { req: TODO; res: TODO; }; 'room/update': { req: TODO; res: TODO; };