Sharkey/packages/frontend/src/pages/instance-info.vue

267 lines
9.5 KiB
Vue
Raw Normal View History

<!--
SPDX-FileCopyrightText: syuilo and other misskey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->
2022-06-20 13:49:51 +03:00
<template>
<MkStickyContainer>
<template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template>
2023-05-19 10:20:53 +03:00
<MkSpacer v-if="instance" :contentMax="600" :marginMin="16" :marginMax="32">
2023-01-06 06:40:17 +02:00
<div v-if="tab === 'overview'" class="_gaps_m">
2022-06-20 13:49:51 +03:00
<div class="fnfelxur">
<img :src="faviconUrl" alt="" class="icon"/>
2022-07-20 16:24:26 +03:00
<span class="name">{{ instance.name || `(${i18n.ts.unknown})` }}</span>
2022-06-20 13:49:51 +03:00
</div>
2023-01-05 14:04:56 +02:00
<div style="display: flex; flex-direction: column; gap: 1em;">
<MkKeyValue :copy="host" oneline>
<template #key>Host</template>
<template #value><span class="_monospace"><MkLink :url="`https://${host}`">{{ host }}</MkLink></span></template>
</MkKeyValue>
<MkKeyValue oneline>
<template #key>{{ i18n.ts.software }}</template>
<template #value><span class="_monospace">{{ instance.softwareName || `(${i18n.ts.unknown})` }} / {{ instance.softwareVersion || `(${i18n.ts.unknown})` }}</span></template>
</MkKeyValue>
<MkKeyValue oneline>
<template #key>{{ i18n.ts.administrator }}</template>
<template #value>{{ instance.maintainerName || `(${i18n.ts.unknown})` }} ({{ instance.maintainerEmail || `(${i18n.ts.unknown})` }})</template>
</MkKeyValue>
</div>
2022-06-26 10:57:12 +03:00
<MkKeyValue>
2022-07-20 16:24:26 +03:00
<template #key>{{ i18n.ts.description }}</template>
2022-06-26 10:57:12 +03:00
<template #value>{{ instance.description }}</template>
</MkKeyValue>
2022-06-20 13:49:51 +03:00
<FormSection v-if="iAmModerator">
<template #label>Moderation</template>
2023-01-06 06:40:17 +02:00
<div class="_gaps_s">
<MkSwitch v-model="suspended" :disabled="!instance" @update:modelValue="toggleSuspend">{{ i18n.ts.stopActivityDelivery }}</MkSwitch>
<MkSwitch v-model="isBlocked" :disabled="!meta || !instance" @update:modelValue="toggleBlock">{{ i18n.ts.blockThisInstance }}</MkSwitch>
2023-01-05 14:04:56 +02:00
<MkButton @click="refreshMetadata"><i class="ti ti-refresh"></i> Refresh metadata</MkButton>
</div>
2022-06-20 13:49:51 +03:00
</FormSection>
<FormSection>
<MkKeyValue oneline style="margin: 1em 0;">
2022-07-20 16:24:26 +03:00
<template #key>{{ i18n.ts.registeredAt }}</template>
<template #value><MkTime mode="detail" :time="instance.firstRetrievedAt"/></template>
2022-06-20 13:49:51 +03:00
</MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;">
2022-07-20 16:24:26 +03:00
<template #key>{{ i18n.ts.updatedAt }}</template>
2022-06-20 13:49:51 +03:00
<template #value><MkTime mode="detail" :time="instance.infoUpdatedAt"/></template>
</MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;">
2022-07-20 16:24:26 +03:00
<template #key>{{ i18n.ts.latestRequestReceivedAt }}</template>
2022-06-20 13:49:51 +03:00
<template #value><MkTime v-if="instance.latestRequestReceivedAt" :time="instance.latestRequestReceivedAt"/><span v-else>N/A</span></template>
</MkKeyValue>
</FormSection>
2022-06-20 13:49:51 +03:00
<FormSection>
<MkKeyValue oneline style="margin: 1em 0;">
2022-07-07 12:06:34 +03:00
<template #key>Following (Pub)</template>
<template #value>{{ number(instance.followingCount) }}</template>
</MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;">
<template #key>Followers (Sub)</template>
<template #value>{{ number(instance.followersCount) }}</template>
2022-06-20 13:49:51 +03:00
</MkKeyValue>
</FormSection>
<FormSection>
<template #label>Well-known resources</template>
<FormLink :to="`https://${host}/.well-known/host-meta`" external style="margin-bottom: 8px;">host-meta</FormLink>
<FormLink :to="`https://${host}/.well-known/host-meta.json`" external style="margin-bottom: 8px;">host-meta.json</FormLink>
<FormLink :to="`https://${host}/.well-known/nodeinfo`" external style="margin-bottom: 8px;">nodeinfo</FormLink>
<FormLink :to="`https://${host}/robots.txt`" external style="margin-bottom: 8px;">robots.txt</FormLink>
<FormLink :to="`https://${host}/manifest.json`" external style="margin-bottom: 8px;">manifest.json</FormLink>
</FormSection>
</div>
2023-01-06 06:40:17 +02:00
<div v-else-if="tab === 'chart'" class="_gaps_m">
2022-06-21 11:55:38 +03:00
<div class="cmhjzshl">
<div class="selects">
<MkSelect v-model="chartSrc" style="margin: 0 10px 0 0; flex: 1;">
2022-07-20 16:24:26 +03:00
<option value="instance-requests">{{ i18n.ts._instanceCharts.requests }}</option>
<option value="instance-users">{{ i18n.ts._instanceCharts.users }}</option>
<option value="instance-users-total">{{ i18n.ts._instanceCharts.usersTotal }}</option>
<option value="instance-notes">{{ i18n.ts._instanceCharts.notes }}</option>
<option value="instance-notes-total">{{ i18n.ts._instanceCharts.notesTotal }}</option>
<option value="instance-ff">{{ i18n.ts._instanceCharts.ff }}</option>
<option value="instance-ff-total">{{ i18n.ts._instanceCharts.ffTotal }}</option>
<option value="instance-drive-usage">{{ i18n.ts._instanceCharts.cacheSize }}</option>
<option value="instance-drive-usage-total">{{ i18n.ts._instanceCharts.cacheSizeTotal }}</option>
<option value="instance-drive-files">{{ i18n.ts._instanceCharts.files }}</option>
<option value="instance-drive-files-total">{{ i18n.ts._instanceCharts.filesTotal }}</option>
2022-06-21 11:55:38 +03:00
</MkSelect>
</div>
<div class="charts">
<div class="label">{{ i18n.t('recentNHours', { n: 90 }) }}</div>
<MkChart class="chart" :src="chartSrc" span="hour" :limit="90" :args="{ host: host }" :detailed="true"></MkChart>
<div class="label">{{ i18n.t('recentNDays', { n: 90 }) }}</div>
<MkChart class="chart" :src="chartSrc" span="day" :limit="90" :args="{ host: host }" :detailed="true"></MkChart>
</div>
</div>
</div>
2023-01-06 06:40:17 +02:00
<div v-else-if="tab === 'users'" class="_gaps_m">
<MkPagination v-slot="{items}" :pagination="usersPagination" style="display: grid; grid-template-columns: repeat(auto-fill,minmax(270px,1fr)); grid-gap: 12px;">
<MkA v-for="user in items" :key="user.id" v-tooltip.mfm="`Last posted: ${dateString(user.updatedAt)}`" class="user" :to="`/admin/user/${user.id}`">
<MkUserCardMini :user="user"/>
</MkA>
</MkPagination>
</div>
2023-01-06 06:40:17 +02:00
<div v-else-if="tab === 'raw'" class="_gaps_m">
2022-06-21 11:55:38 +03:00
<MkObjectView tall :value="instance">
</MkObjectView>
</div>
2022-06-20 13:49:51 +03:00
</MkSpacer>
</MkStickyContainer>
</template>
<script lang="ts" setup>
import { } from 'vue';
import * as Misskey from 'misskey-js';
import MkChart from '@/components/MkChart.vue';
import MkObjectView from '@/components/MkObjectView.vue';
2022-01-04 08:36:14 +02:00
import FormLink from '@/components/form/link.vue';
import MkLink from '@/components/MkLink.vue';
import MkButton from '@/components/MkButton.vue';
2022-01-04 08:36:14 +02:00
import FormSection from '@/components/form/section.vue';
import MkKeyValue from '@/components/MkKeyValue.vue';
2023-01-07 08:09:46 +02:00
import MkSelect from '@/components/MkSelect.vue';
2023-01-07 07:59:54 +02:00
import MkSwitch from '@/components/MkSwitch.vue';
2021-11-11 19:02:25 +02:00
import * as os from '@/os';
import number from '@/filters/number';
import { iAmModerator, iAmAdmin } from '@/account';
import { definePageMetadata } from '@/scripts/page-metadata';
2022-06-21 11:55:38 +03:00
import { i18n } from '@/i18n';
import MkUserCardMini from '@/components/MkUserCardMini.vue';
import MkPagination from '@/components/MkPagination.vue';
import { getProxiedImageUrlNullable } from '@/scripts/media-proxy';
import { dateString } from '@/filters/date';
const props = defineProps<{
host: string;
}>();
2022-06-21 11:55:38 +03:00
let tab = $ref('overview');
2022-06-21 18:10:34 +03:00
let chartSrc = $ref('instance-requests');
let meta = $ref<Misskey.entities.AdminInstanceMetadata | null>(null);
let instance = $ref<Misskey.entities.Instance | null>(null);
let suspended = $ref(false);
let isBlocked = $ref(false);
let faviconUrl = $ref<string | null>(null);
const usersPagination = {
2022-06-30 09:32:11 +03:00
endpoint: iAmModerator ? 'admin/show-users' : 'users' as const,
limit: 10,
params: {
sort: '+updatedAt',
state: 'all',
hostname: props.host,
},
offsetMode: true,
};
async function fetch(): Promise<void> {
if (iAmAdmin) {
meta = await os.api('admin/meta');
}
instance = await os.api('federation/show-instance', {
host: props.host,
});
suspended = instance.isSuspended;
isBlocked = instance.isBlocked;
faviconUrl = getProxiedImageUrlNullable(instance.faviconUrl, 'preview') ?? getProxiedImageUrlNullable(instance.iconUrl, 'preview');
}
async function toggleBlock(): Promise<void> {
if (!meta) throw new Error('No meta?');
if (!instance) throw new Error('No instance?');
const { host } = instance;
await os.api('admin/update-meta', {
blockedHosts: isBlocked ? meta.blockedHosts.concat([host]) : meta.blockedHosts.filter(x => x !== host),
});
}
2022-01-04 08:36:14 +02:00
async function toggleSuspend(): Promise<void> {
if (!instance) throw new Error('No instance?');
await os.api('admin/federation/update-instance', {
host: instance.host,
isSuspended: suspended,
});
}
2022-01-04 08:36:14 +02:00
function refreshMetadata(): void {
if (!instance) throw new Error('No instance?');
os.api('admin/federation/refresh-remote-instance-metadata', {
host: instance.host,
});
os.alert({
text: 'Refresh requested',
});
}
fetch();
2022-06-20 13:49:51 +03:00
const headerActions = $computed(() => [{
text: `https://${props.host}`,
icon: 'ti ti-external-link',
2022-06-20 13:49:51 +03:00
handler: () => {
window.open(`https://${props.host}`, '_blank');
},
}]);
2022-06-21 11:55:38 +03:00
const headerTabs = $computed(() => [{
key: 'overview',
2022-06-21 11:55:38 +03:00
title: i18n.ts.overview,
icon: 'ti ti-info-circle',
2022-06-21 11:55:38 +03:00
}, {
key: 'chart',
2022-06-21 11:55:38 +03:00
title: i18n.ts.charts,
icon: 'ti ti-chart-line',
}, {
key: 'users',
title: i18n.ts.users,
icon: 'ti ti-users',
2022-06-21 11:55:38 +03:00
}, {
key: 'raw',
2022-06-29 08:19:40 +03:00
title: 'Raw',
icon: 'ti ti-code',
2022-06-21 11:55:38 +03:00
}]);
definePageMetadata({
title: props.host,
icon: 'ti ti-server',
});
</script>
2021-04-16 15:47:12 +03:00
<style lang="scss" scoped>
2021-04-16 15:47:12 +03:00
.fnfelxur {
2022-06-26 10:57:12 +03:00
display: flex;
align-items: center;
2021-04-25 06:31:11 +03:00
> .icon {
2021-04-16 15:47:12 +03:00
display: block;
2022-06-26 10:57:12 +03:00
margin: 0 16px 0 0;
2021-04-16 15:47:12 +03:00
height: 64px;
border-radius: 8px;
}
2022-06-26 10:57:12 +03:00
> .name {
word-break: break-all;
}
2021-04-16 15:47:12 +03:00
}
.cmhjzshl {
> .selects {
display: flex;
2022-01-04 08:36:14 +02:00
margin: 0 0 16px 0;
2021-04-16 15:47:12 +03:00
}
2022-06-21 11:55:38 +03:00
> .charts {
> .label {
margin-bottom: 12px;
font-weight: bold;
}
}
2021-04-16 15:47:12 +03:00
}
</style>