From 89e27d8418f89cc65fe58b584aa5484487bc3d35 Mon Sep 17 00:00:00 2001 From: amybones Date: Tue, 4 Apr 2023 03:46:23 +0000 Subject: [PATCH] fix: toggling the blocking state from the instance-info admin view (#9809) Because the admin meta information was never loaded on this page, no amount of toggling the block or suspend sliders on the instance-info page (e.g. `https://calckey.example.com/instance-info/instance.tld`) will result in the instance actually being added to the blocklist. You could still do it from the bulk blocklist management page, but that can get unwieldy quickly if you just want to do a quick block of an instance. Co-authored-by: amy bones Reviewed-on: https://codeberg.org/calckey/calckey/pulls/9809 Co-authored-by: amybones Co-committed-by: amybones --- .../server/api/endpoints/admin/update-meta.ts | 7 ++- packages/client/src/pages/instance-info.vue | 50 ++++++++++++++----- 2 files changed, 43 insertions(+), 14 deletions(-) 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 28aac4a4d..d3a39acd2 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 15c9a7cd8..f84e3b014 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, }); }