From 9022ab9f2a5872c02f6d20f1d96ebc1bee6dd43f Mon Sep 17 00:00:00 2001 From: Johann150 Date: Mon, 10 Oct 2022 17:36:13 +0200 Subject: [PATCH 1/3] backend: ignore detail parameter on meta endpoint Also allow meta endpoint to be fetched via GET. Changelog: Removed --- .../backend/src/server/api/endpoints/meta.ts | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/meta.ts b/packages/backend/src/server/api/endpoints/meta.ts index 0d11c5a92..cbf74ef04 100644 --- a/packages/backend/src/server/api/endpoints/meta.ts +++ b/packages/backend/src/server/api/endpoints/meta.ts @@ -10,6 +10,9 @@ export const meta = { requireCredential: false, + allowGet: true, + cacheSec: 60, + res: { type: 'object', optional: false, nullable: false, @@ -253,7 +256,12 @@ export const meta = { export const paramDef = { type: 'object', properties: { - detail: { type: 'boolean', default: true }, + detail: { + deprecated: true, + description: 'This parameter is ignored. You will always get all details (as if it was `true`).', + type: 'boolean', + default: true, + }, }, required: [], } as const; @@ -276,7 +284,7 @@ export default define(meta, paramDef, async (ps, me) => { }, }); - const response: any = { + return { maintainerName: instance.maintainerName, maintainerEmail: instance.maintainerEmail, @@ -317,21 +325,16 @@ export default define(meta, paramDef, async (ps, me) => { translatorAvailable: instance.deeplAuthKey != null, - ...(ps.detail ? { - pinnedPages: instance.pinnedPages, - pinnedClipId: instance.pinnedClipId, - cacheRemoteFiles: instance.cacheRemoteFiles, - requireSetup: (await Users.countBy({ - host: IsNull(), - })) === 0, - } : {}), - }; + pinnedPages: instance.pinnedPages, + pinnedClipId: instance.pinnedClipId, + cacheRemoteFiles: instance.cacheRemoteFiles, + requireSetup: (await Users.countBy({ + host: IsNull(), + })) === 0, - if (ps.detail) { - const proxyAccount = instance.proxyAccountId ? await Users.pack(instance.proxyAccountId).catch(() => null) : null; + proxyAccountName: instance.proxyAccountId ? (await Users.pack(instance.proxyAccountId).catch(() => null))?.username : null, - response.proxyAccountName = proxyAccount ? proxyAccount.username : null; - response.features = { + features: { registration: !instance.disableRegistration, localTimeLine: !instance.disableLocalTimeline, globalTimeLine: !instance.disableGlobalTimeline, @@ -345,8 +348,6 @@ export default define(meta, paramDef, async (ps, me) => { discord: instance.enableDiscordIntegration, serviceWorker: instance.enableServiceWorker, miauth: true, - }; - } - - return response; + }, + }; }); From 4f9504d135546e8c1dc11f5c56966866c48dd7f2 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Mon, 10 Oct 2022 17:36:50 +0200 Subject: [PATCH 2/3] client: fetch meta via GET --- packages/client/src/instance.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/client/src/instance.ts b/packages/client/src/instance.ts index b4bc07578..71a293005 100644 --- a/packages/client/src/instance.ts +++ b/packages/client/src/instance.ts @@ -1,6 +1,6 @@ import { computed, reactive } from 'vue'; import * as foundkey from 'foundkey-js'; -import { api } from '@/os'; +import { apiGet } from '@/os'; // TODO: 他のタブと永続化されたstateを同期 @@ -13,13 +13,7 @@ export const instance: foundkey.entities.InstanceMetadata = reactive(instanceDat }); export async function fetchInstance(): Promise { - const meta = await api('meta', { - detail: false, - }); - - for (const [k, v] of Object.entries(meta)) { - instance[k] = v; - } + Object.assign(instance, await apiGet('meta')); localStorage.setItem('instance', JSON.stringify(instance)); } From 2c411d59f4f54c70990bbba7711b30ed612e6574 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Tue, 11 Oct 2022 10:46:25 +0200 Subject: [PATCH 3/3] client: use cached instance information --- packages/client/src/components/featured-photos.vue | 12 ++---------- packages/client/src/pages/_error_.vue | 11 ++++------- packages/client/src/pages/welcome.entrance.a.vue | 12 ++++-------- packages/client/src/pages/welcome.vue | 11 ++--------- packages/client/src/ui/visitor/b.vue | 5 ----- 5 files changed, 12 insertions(+), 39 deletions(-) diff --git a/packages/client/src/components/featured-photos.vue b/packages/client/src/components/featured-photos.vue index ac96c1a4d..d75da9684 100644 --- a/packages/client/src/components/featured-photos.vue +++ b/packages/client/src/components/featured-photos.vue @@ -1,17 +1,9 @@