diff --git a/packages/frontend/src/pages/instance-info.vue b/packages/frontend/src/pages/instance-info.vue index 54f2cd7def..24355c0556 100644 --- a/packages/frontend/src/pages/instance-info.vue +++ b/packages/frontend/src/pages/instance-info.vue @@ -34,8 +34,8 @@ SPDX-License-Identifier: AGPL-3.0-only
- {{ i18n.ts.stopActivityDelivery }} - {{ i18n.ts.blockThisInstance }} + {{ i18n.ts.stopActivityDelivery }} + {{ i18n.ts.blockThisInstance }} Refresh metadata
@@ -129,7 +129,7 @@ import MkSelect from '@/components/MkSelect.vue'; import MkSwitch from '@/components/MkSwitch.vue'; import * as os from '@/os'; import number from '@/filters/number'; -import { iAmModerator } from '@/account'; +import { iAmModerator, iAmAdmin } from '@/account'; import { definePageMetadata } from '@/scripts/page-metadata'; import { i18n } from '@/i18n'; import MkUserCardMini from '@/components/MkUserCardMini.vue'; @@ -143,11 +143,11 @@ const props = defineProps<{ let tab = $ref('overview'); let chartSrc = $ref('instance-requests'); -let meta = $ref(null); +let meta = $ref(null); let instance = $ref(null); let suspended = $ref(false); let isBlocked = $ref(false); -let faviconUrl = $ref(null); +let faviconUrl = $ref(null); const usersPagination = { endpoint: iAmModerator ? 'admin/show-users' : 'users' as const, @@ -160,7 +160,10 @@ const usersPagination = { offsetMode: true, }; -async function fetch() { +async function fetch(): Promise { + if (iAmAdmin) { + meta = await os.api('admin/meta'); + } instance = await os.api('federation/show-instance', { host: props.host, }); @@ -169,21 +172,25 @@ async function fetch() { faviconUrl = getProxiedImageUrlNullable(instance.faviconUrl, 'preview') ?? getProxiedImageUrlNullable(instance.iconUrl, 'preview'); } -async function toggleBlock(ev) { - if (meta == null) return; +async function toggleBlock(): Promise { + 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([instance.host]) : meta.blockedHosts.filter(x => x !== instance.host), + blockedHosts: isBlocked ? meta.blockedHosts.concat([host]) : meta.blockedHosts.filter(x => x !== host), }); } -async function toggleSuspend(v) { +async function toggleSuspend(): Promise { + if (!instance) throw new Error('No instance?'); await os.api('admin/federation/update-instance', { host: instance.host, isSuspended: suspended, }); } -function refreshMetadata() { +function refreshMetadata(): void { + if (!instance) throw new Error('No instance?'); os.api('admin/federation/refresh-remote-instance-metadata', { host: instance.host, }); diff --git a/packages/misskey-js/etc/misskey-js.api.md b/packages/misskey-js/etc/misskey-js.api.md index e62cd7451f..2c28e7f9a6 100644 --- a/packages/misskey-js/etc/misskey-js.api.md +++ b/packages/misskey-js/etc/misskey-js.api.md @@ -17,6 +17,11 @@ export type Acct = { // @public (undocumented) type Ad = TODO_2; +// @public (undocumented) +type AdminInstanceMetadata = DetailedInstanceMetadata & { + blockedHosts: string[]; +}; + // @public (undocumented) type Announcement = { id: ID; @@ -334,8 +339,8 @@ export type Endpoints = { res: TODO; }; 'admin/meta': { - req: TODO; - res: TODO; + req: NoParams; + res: AdminInstanceMetadata; }; 'admin/reset-password': { req: TODO; @@ -2248,6 +2253,7 @@ declare namespace entities { LiteInstanceMetadata, DetailedInstanceMetadata, InstanceMetadata, + AdminInstanceMetadata, ServerInfo, Stats, Page, @@ -2339,7 +2345,7 @@ type ID = string; // @public (undocumented) type Instance = { id: ID; - caughtAt: DateString; + firstRetrievedAt: DateString; host: string; usersCount: number; notesCount: number; @@ -2353,6 +2359,7 @@ type Instance = { lastCommunicatedAt: DateString; isNotResponding: boolean; isSuspended: boolean; + isBlocked: boolean; softwareName: string | null; softwareVersion: string | null; openRegistrations: boolean | null; diff --git a/packages/misskey-js/src/api.types.ts b/packages/misskey-js/src/api.types.ts index fcfa0ed896..42655b2cea 100644 --- a/packages/misskey-js/src/api.types.ts +++ b/packages/misskey-js/src/api.types.ts @@ -2,7 +2,7 @@ import type { Ad, Announcement, Antenna, App, AuthSession, Blocking, Channel, Clip, DateString, DetailedInstanceMetadata, DriveFile, DriveFolder, Following, FollowingFolloweePopulated, FollowingFollowerPopulated, FollowRequest, GalleryPost, Instance, LiteInstanceMetadata, MeDetailed, - Note, NoteFavorite, OriginType, Page, ServerInfo, Stats, User, UserDetailed, MeSignup, UserGroup, UserList, UserSorting, Notification, NoteReaction, Signin, MessagingMessage, Invite, InviteLimit, + Note, NoteFavorite, OriginType, Page, ServerInfo, Stats, User, UserDetailed, MeSignup, UserGroup, UserList, UserSorting, Notification, NoteReaction, Signin, MessagingMessage, Invite, InviteLimit, AdminInstanceMetadata, } from './entities.js'; type TODO = Record | null; @@ -20,7 +20,7 @@ export type Endpoints = { 'admin/get-table-stats': { req: TODO; res: TODO; }; 'admin/invite': { req: TODO; res: TODO; }; 'admin/logs': { req: TODO; res: TODO; }; - 'admin/meta': { req: TODO; res: TODO; }; + 'admin/meta': { req: NoParams; res: AdminInstanceMetadata; }; 'admin/reset-password': { req: TODO; res: TODO; }; 'admin/resolve-abuse-user-report': { req: TODO; res: TODO; }; 'admin/resync-chart': { req: TODO; res: TODO; }; diff --git a/packages/misskey-js/src/entities.ts b/packages/misskey-js/src/entities.ts index a338fa9ad9..4564d77051 100644 --- a/packages/misskey-js/src/entities.ts +++ b/packages/misskey-js/src/entities.ts @@ -351,6 +351,11 @@ export type DetailedInstanceMetadata = LiteInstanceMetadata & { export type InstanceMetadata = LiteInstanceMetadata | DetailedInstanceMetadata; +export type AdminInstanceMetadata = DetailedInstanceMetadata & { + // TODO: There are more fields. + blockedHosts: string[]; +}; + export type ServerInfo = { machine: string; cpu: { @@ -489,7 +494,7 @@ export type Blocking = { export type Instance = { id: ID; - caughtAt: DateString; + firstRetrievedAt: DateString; host: string; usersCount: number; notesCount: number; @@ -503,6 +508,7 @@ export type Instance = { lastCommunicatedAt: DateString; isNotResponding: boolean; isSuspended: boolean; + isBlocked: boolean; softwareName: string | null; softwareVersion: string | null; openRegistrations: boolean | null;