refactor(frontend): widgets/server-metric内の型エラーを除去 (#12937)

This commit is contained in:
zyoshoka
2024-01-07 23:56:46 +09:00
committed by GitHub
parent fd519f5def
commit 0e536bdd86
13 changed files with 103 additions and 30 deletions

View File

@@ -80,13 +80,13 @@ import * as Misskey from 'misskey-js';
import { v4 as uuid } from 'uuid';
const props = defineProps<{
connection: any,
connection: Misskey.ChannelConnection<Misskey.Channels['serverStats']>,
meta: Misskey.entities.ServerInfoResponse
}>();
const viewBoxX = ref<number>(50);
const viewBoxY = ref<number>(30);
const stats = ref<any[]>([]);
const stats = ref<Misskey.entities.ServerStats[]>([]);
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);
}
}

View File

@@ -20,13 +20,13 @@ import * as Misskey from 'misskey-js';
import XPie from './pie.vue';
const props = defineProps<{
connection: any,
connection: Misskey.ChannelConnection<Misskey.Channels['serverStats']>,
meta: Misskey.entities.ServerInfoResponse
}>();
const usage = ref<number>(0);
function onStats(stats) {
function onStats(stats: Misskey.entities.ServerStats) {
usage.value = stats.cpu;
}

View File

@@ -22,7 +22,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<script lang="ts" setup>
import { onUnmounted, ref } from 'vue';
import * as Misskey from 'misskey-js';
import { useWidgetPropsManager, Widget, WidgetComponentExpose } from '../widget.js';
import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from '../widget.js';
import XCpuMemory from './cpu-mem.vue';
import XNet from './net.vue';
import XCpu from './cpu.vue';
@@ -54,11 +54,8 @@ const widgetPropsDef = {
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
//const props = defineProps<WidgetComponentProps<WidgetProps>>();
//const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
const props = defineProps<{ widget?: Widget<WidgetProps>; }>();
const emit = defineEmits<{ (ev: 'updateProps', props: WidgetProps); }>();
const props = defineProps<WidgetComponentProps<WidgetProps>>();
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
const { widgetProps, configure, save } = useWidgetPropsManager(name,
widgetPropsDef,

View File

@@ -22,7 +22,7 @@ import XPie from './pie.vue';
import bytes from '@/filters/bytes.js';
const props = defineProps<{
connection: any,
connection: Misskey.ChannelConnection<Misskey.Channels['serverStats']>,
meta: Misskey.entities.ServerInfoResponse
}>();
@@ -31,7 +31,7 @@ const total = ref<number>(0);
const used = ref<number>(0);
const free = ref<number>(0);
function onStats(stats) {
function onStats(stats: Misskey.entities.ServerStats) {
usage.value = stats.mem.active / props.meta.mem.total;
total.value = props.meta.mem.total;
used.value = stats.mem.active;

View File

@@ -54,13 +54,13 @@ import * as Misskey from 'misskey-js';
import bytes from '@/filters/bytes.js';
const props = defineProps<{
connection: any,
connection: Misskey.ChannelConnection<Misskey.Channels['serverStats']>,
meta: Misskey.entities.ServerInfoResponse
}>();
const viewBoxX = ref<number>(50);
const viewBoxY = ref<number>(30);
const stats = ref<any[]>([]);
const stats = ref<Misskey.entities.ServerStats[]>([]);
const inPolylinePoints = ref<string>('');
const outPolylinePoints = ref<string>('');
const inPolygonPoints = ref<string>('');
@@ -77,6 +77,7 @@ onMounted(() => {
props.connection.on('statsLog', onStatsLog);
props.connection.send('requestLog', {
id: Math.random().toString().substring(2, 10),
length: 50,
});
});
@@ -85,7 +86,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();
@@ -109,8 +110,8 @@ function onStats(connStats) {
outRecent.value = connStats.net.tx;
}
function onStatsLog(statsLog) {
for (const revStats of [...statsLog].reverse()) {
function onStatsLog(statsLog: Misskey.entities.ServerStatsLog) {
for (const revStats of statsLog.reverse()) {
onStats(revStats);
}
}