diff --git a/packages/backend/src/daemons/ServerStatsService.ts b/packages/backend/src/daemons/ServerStatsService.ts index c5ef9b2fa3..4c55acea5a 100644 --- a/packages/backend/src/daemons/ServerStatsService.ts +++ b/packages/backend/src/daemons/ServerStatsService.ts @@ -37,7 +37,7 @@ export class ServerStatsService implements OnApplicationShutdown { const log = [] as any[]; ev.on('requestServerStatsLog', x => { - ev.emit(`serverStatsLog:${x.id}`, log.slice(0, x.length ?? 50)); + ev.emit(`serverStatsLog:${x.id}`, log.slice(0, x.length)); }); const tick = async () => { diff --git a/packages/frontend/src/scripts/misskey-api.ts b/packages/frontend/src/scripts/misskey-api.ts index e71c5dd592..337fa15113 100644 --- a/packages/frontend/src/scripts/misskey-api.ts +++ b/packages/frontend/src/scripts/misskey-api.ts @@ -10,12 +10,17 @@ import { $i } from '@/account.js'; export const pendingApiRequestsCount = ref(0); // Implements Misskey.api.ApiClient.request -export function misskeyApi( +export function misskeyApi< + ResT = void, + E extends keyof Misskey.Endpoints = keyof Misskey.Endpoints, + P extends Misskey.Endpoints[E]['req'] = Misskey.Endpoints[E]['req'], + _ResT = ResT extends void ? Misskey.api.SwitchCaseResponseType : ResT, +>( endpoint: E, data: P = {} as any, token?: string | null | undefined, signal?: AbortSignal, -): Promise> { +): Promise<_ResT> { if (endpoint.includes('://')) throw new Error('invalid endpoint'); pendingApiRequestsCount.value++; @@ -23,7 +28,7 @@ export function misskeyApi((resolve, reject) => { + const promise = new Promise<_ResT>((resolve, reject) => { // Append a credential if ($i) (data as any).i = $i.token; if (token !== undefined) (data as any).i = token; @@ -44,7 +49,7 @@ export function misskeyApi undefined } else { reject(body.error); } @@ -57,10 +62,15 @@ export function misskeyApi( +export function misskeyApiGet< + ResT = void, + E extends keyof Misskey.Endpoints = keyof Misskey.Endpoints, + P extends Misskey.Endpoints[E]['req'] = Misskey.Endpoints[E]['req'], + _ResT = ResT extends void ? Misskey.api.SwitchCaseResponseType : ResT, +>( endpoint: E, data: P = {} as any, -): Promise> { +): Promise<_ResT> { pendingApiRequestsCount.value++; const onFinally = () => { @@ -69,7 +79,7 @@ export function misskeyApiGet((resolve, reject) => { + const promise = new Promise<_ResT>((resolve, reject) => { // Send request window.fetch(`${apiUrl}/${endpoint}?${query}`, { method: 'GET', @@ -81,7 +91,7 @@ export function misskeyApiGet undefined } else { reject(body.error); } diff --git a/packages/frontend/src/widgets/server-metric/cpu-mem.vue b/packages/frontend/src/widgets/server-metric/cpu-mem.vue index f13b6a370d..ee720bd9d7 100644 --- a/packages/frontend/src/widgets/server-metric/cpu-mem.vue +++ b/packages/frontend/src/widgets/server-metric/cpu-mem.vue @@ -80,13 +80,13 @@ import * as Misskey from 'misskey-js'; import { v4 as uuid } from 'uuid'; const props = defineProps<{ - connection: any, + connection: Misskey.ChannelConnection, meta: Misskey.entities.ServerInfoResponse }>(); const viewBoxX = ref(50); const viewBoxY = ref(30); -const stats = ref([]); +const stats = ref([]); const cpuGradientId = uuid(); const cpuMaskId = uuid(); const memGradientId = uuid(); @@ -107,6 +107,7 @@ onMounted(() => { props.connection.on('statsLog', onStatsLog); props.connection.send('requestLog', { id: Math.random().toString().substring(2, 10), + length: 50, }); }); @@ -115,7 +116,7 @@ onBeforeUnmount(() => { props.connection.off('statsLog', onStatsLog); }); -function onStats(connStats) { +function onStats(connStats: Misskey.entities.ServerStats) { stats.value.push(connStats); if (stats.value.length > 50) stats.value.shift(); @@ -136,8 +137,8 @@ function onStats(connStats) { memP.value = (connStats.mem.active / props.meta.mem.total * 100).toFixed(0); } -function onStatsLog(statsLog) { - for (const revStats of [...statsLog].reverse()) { +function onStatsLog(statsLog: Misskey.entities.ServerStatsLog) { + for (const revStats of statsLog.reverse()) { onStats(revStats); } } diff --git a/packages/frontend/src/widgets/server-metric/cpu.vue b/packages/frontend/src/widgets/server-metric/cpu.vue index c7fd0e9023..3778c4318e 100644 --- a/packages/frontend/src/widgets/server-metric/cpu.vue +++ b/packages/frontend/src/widgets/server-metric/cpu.vue @@ -20,13 +20,13 @@ import * as Misskey from 'misskey-js'; import XPie from './pie.vue'; const props = defineProps<{ - connection: any, + connection: Misskey.ChannelConnection, meta: Misskey.entities.ServerInfoResponse }>(); const usage = ref(0); -function onStats(stats) { +function onStats(stats: Misskey.entities.ServerStats) { usage.value = stats.cpu; } diff --git a/packages/frontend/src/widgets/server-metric/index.vue b/packages/frontend/src/widgets/server-metric/index.vue index f5e80b0d21..990590e0d1 100644 --- a/packages/frontend/src/widgets/server-metric/index.vue +++ b/packages/frontend/src/widgets/server-metric/index.vue @@ -22,7 +22,7 @@ SPDX-License-Identifier: AGPL-3.0-only