diff --git a/packages/backend/src/server/api/endpoints/admin/update-meta.ts b/packages/backend/src/server/api/endpoints/admin/update-meta.ts index 28aac4a4d4..d3a39acd2d 100644 --- a/packages/backend/src/server/api/endpoints/admin/update-meta.ts +++ b/packages/backend/src/server/api/endpoints/admin/update-meta.ts @@ -209,7 +209,12 @@ export default define(meta, paramDef, async (ps, me) => { } if (Array.isArray(ps.blockedHosts)) { - set.blockedHosts = ps.blockedHosts.filter(Boolean); + let lastValue = ''; + set.blockedHosts = ps.blockedHosts.sort().filter(h => { + const lv = lastValue; + lastValue = h; + return h !== '' && h !== lv; + }); } if (ps.themeColor !== undefined) { diff --git a/packages/client/src/pages/instance-info.vue b/packages/client/src/pages/instance-info.vue index 15c9a7cd8b..f84e3b0147 100644 --- a/packages/client/src/pages/instance-info.vue +++ b/packages/client/src/pages/instance-info.vue @@ -35,8 +35,10 @@ - {{ i18n.ts.stopActivityDelivery }} - {{ i18n.ts.blockThisInstance }} + + {{ i18n.ts.stopActivityDelivery }} + {{ i18n.ts.blockThisInstance }} + Refresh metadata @@ -158,6 +160,13 @@ import 'swiper/scss'; import 'swiper/scss/virtual'; import { getProxiedImageUrlNullable } from '@/scripts/media-proxy'; +type AugmentedInstanceMetadata = misskey.entities.DetailedInstanceMetadata & { + blockedHosts: string[]; +}; +type AugmentedInstance = misskey.entities.Instance & { + isBlocked: boolean; +}; + const props = defineProps<{ host: string; }>(); @@ -168,8 +177,8 @@ let tab = $ref(tabs[0]); watch($$(tab), () => (syncSlide(tabs.indexOf(tab)))); let chartSrc = $ref('instance-requests'); -let meta = $ref(null); -let instance = $ref(null); +let meta = $ref(null); +let instance = $ref(null); let suspended = $ref(false); let isBlocked = $ref(false); let faviconUrl = $ref(null); @@ -185,19 +194,34 @@ const usersPagination = { offsetMode: true, }; -async function fetch() { - 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 init() { + meta = await os.api('admin/meta'); } -async function toggleBlock(ev) { +async function fetch() { + instance = (await os.api('federation/show-instance', { + host: props.host, + })) as AugmentedInstance; + suspended = instance.isSuspended; + isBlocked = instance.isBlocked; + faviconUrl = + getProxiedImageUrlNullable(instance.faviconUrl, 'preview') ?? + getProxiedImageUrlNullable(instance.iconUrl, 'preview'); +} + +async function toggleBlock() { if (meta == null) return; + if (!instance) { + throw new Error(`Instance info not loaded`); + } + let blockedHosts: string[]; + if (isBlocked) { + blockedHosts = meta.blockedHosts.concat([instance.host]); + } else { + blockedHosts = meta.blockedHosts.filter((x) => x !== instance!.host); + } await os.api('admin/update-meta', { - blockedHosts: isBlocked ? meta.blockedHosts.concat([instance.host]) : meta.blockedHosts.filter(x => x !== instance.host), + blockedHosts, }); }