Skip to content

Commit

Permalink
fix(frontend): instance infoページで不必要なapiリクエストが飛ぶのを抑止 (#14515)
Browse files Browse the repository at this point in the history
* fix(frontend): instance infoページで不必要なapiリクエストが飛ぶのを抑止

* fix
  • Loading branch information
kakkokari-gtyih authored Sep 6, 2024
1 parent 8d19bdb commit 567acea
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 32 deletions.
50 changes: 26 additions & 24 deletions packages/frontend/src/components/MkChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,8 @@ SPDX-License-Identifier: AGPL-3.0-only
</div>
</template>

<script lang="ts" setup>
/* eslint-disable id-denylist --
Chart.js has a `data` attribute in most chart definitions, which triggers the
id-denylist violation when setting it. This is causing about 60+ lint issues.
As this is part of Chart.js's API it makes sense to disable the check here.
*/
import { onMounted, ref, shallowRef, watch } from 'vue';
import { Chart } from 'chart.js';
import * as Misskey from 'misskey-js';
import { misskeyApiGet } from '@/scripts/misskey-api.js';
import { defaultStore } from '@/store.js';
import { useChartTooltip } from '@/scripts/use-chart-tooltip.js';
import { chartVLine } from '@/scripts/chart-vline.js';
import { alpha } from '@/scripts/color.js';
import date from '@/filters/date.js';
import bytes from '@/filters/bytes.js';
import { initChart } from '@/scripts/init-chart.js';
import { chartLegend } from '@/scripts/chart-legend.js';
import MkChartLegend from '@/components/MkChartLegend.vue';

initChart();

type ChartSrc =
<script lang="ts">
export type ChartSrc =
| 'federation'
| 'ap-request'
| 'users'
Expand All @@ -62,7 +41,30 @@ type ChartSrc =
| 'per-user-pv'
| 'per-user-following'
| 'per-user-followers'
| 'per-user-drive'
| 'per-user-drive';
</script>

<script lang="ts" setup>
/* eslint-disable id-denylist --
Chart.js has a `data` attribute in most chart definitions, which triggers the
id-denylist violation when setting it. This is causing about 60+ lint issues.
As this is part of Chart.js's API it makes sense to disable the check here.
*/
import { onMounted, ref, shallowRef, watch } from 'vue';
import { Chart } from 'chart.js';
import * as Misskey from 'misskey-js';
import { misskeyApiGet } from '@/scripts/misskey-api.js';
import { defaultStore } from '@/store.js';
import { useChartTooltip } from '@/scripts/use-chart-tooltip.js';
import { chartVLine } from '@/scripts/chart-vline.js';
import { alpha } from '@/scripts/color.js';
import date from '@/filters/date.js';
import bytes from '@/filters/bytes.js';
import { initChart } from '@/scripts/init-chart.js';
import { chartLegend } from '@/scripts/chart-legend.js';
import MkChartLegend from '@/components/MkChartLegend.vue';

initChart();

const props = withDefaults(defineProps<{
src: ChartSrc;
Expand Down
25 changes: 17 additions & 8 deletions packages/frontend/src/pages/instance-info.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<script lang="ts" setup>
import { ref, computed, watch } from 'vue';
import * as Misskey from 'misskey-js';
import MkChart from '@/components/MkChart.vue';
import MkChart, { type ChartSrc } from '@/components/MkChart.vue';
import MkObjectView from '@/components/MkObjectView.vue';
import FormLink from '@/components/form/link.vue';
import MkLink from '@/components/MkLink.vue';
Expand All @@ -150,7 +150,7 @@ import { iAmModerator, iAmAdmin } from '@/account.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { i18n } from '@/i18n.js';
import MkUserCardMini from '@/components/MkUserCardMini.vue';
import MkPagination from '@/components/MkPagination.vue';
import MkPagination, { type Paging } from '@/components/MkPagination.vue';
import MkHorizontalSwipe from '@/components/MkHorizontalSwipe.vue';
import { getProxiedImageUrlNullable } from '@/scripts/media-proxy.js';
import { dateString } from '@/filters/date.js';
Expand All @@ -162,7 +162,7 @@ const props = defineProps<{

const tab = ref('overview');

const chartSrc = ref('instance-requests');
const chartSrc = ref<ChartSrc>('instance-requests');
const meta = ref<Misskey.entities.AdminMetaResponse | null>(null);
const instance = ref<Misskey.entities.FederationInstance | null>(null);
const suspensionState = ref<'none' | 'manuallySuspended' | 'goneSuspended' | 'autoSuspendedForNotResponding'>('none');
Expand All @@ -173,19 +173,22 @@ const faviconUrl = ref<string | null>(null);
const moderationNote = ref('');

const usersPagination = {
endpoint: iAmModerator ? 'admin/show-users' : 'users' as const,
endpoint: iAmModerator ? 'admin/show-users' : 'users',
limit: 10,
params: {
sort: '+updatedAt',
state: 'all',
hostname: props.host,
},
offsetMode: true,
};
} satisfies Paging;

watch(moderationNote, async () => {
await misskeyApi('admin/federation/update-instance', { host: instance.value.host, moderationNote: moderationNote.value });
});
if (iAmModerator) {
watch(moderationNote, async () => {
if (instance.value == null) return;
await misskeyApi('admin/federation/update-instance', { host: instance.value.host, moderationNote: moderationNote.value });
});
}

async function fetch(): Promise<void> {
if (iAmAdmin) {
Expand All @@ -203,6 +206,7 @@ async function fetch(): Promise<void> {
}

async function toggleBlock(): Promise<void> {
if (!iAmAdmin) return;
if (!meta.value) throw new Error('No meta?');
if (!instance.value) throw new Error('No instance?');
const { host } = instance.value;
Expand All @@ -212,6 +216,7 @@ async function toggleBlock(): Promise<void> {
}

async function toggleSilenced(): Promise<void> {
if (!iAmAdmin) return;
if (!meta.value) throw new Error('No meta?');
if (!instance.value) throw new Error('No instance?');
const { host } = instance.value;
Expand All @@ -222,6 +227,7 @@ async function toggleSilenced(): Promise<void> {
}

async function toggleMediaSilenced(): Promise<void> {
if (!iAmAdmin) return;
if (!meta.value) throw new Error('No meta?');
if (!instance.value) throw new Error('No instance?');
const { host } = instance.value;
Expand All @@ -232,6 +238,7 @@ async function toggleMediaSilenced(): Promise<void> {
}

async function stopDelivery(): Promise<void> {
if (!iAmModerator) return;
if (!instance.value) throw new Error('No instance?');
suspensionState.value = 'manuallySuspended';
await misskeyApi('admin/federation/update-instance', {
Expand All @@ -241,6 +248,7 @@ async function stopDelivery(): Promise<void> {
}

async function resumeDelivery(): Promise<void> {
if (!iAmModerator) return;
if (!instance.value) throw new Error('No instance?');
suspensionState.value = 'none';
await misskeyApi('admin/federation/update-instance', {
Expand All @@ -250,6 +258,7 @@ async function resumeDelivery(): Promise<void> {
}

function refreshMetadata(): void {
if (!iAmModerator) return;
if (!instance.value) throw new Error('No instance?');
misskeyApi('admin/federation/refresh-remote-instance-metadata', {
host: instance.value.host,
Expand Down

0 comments on commit 567acea

Please sign in to comment.