Merge pull request 'refactor meta API endpoint' (#196) from refactor/api/meta into main

This commit is contained in:
Norm 2022-10-11 17:20:51 +00:00
commit 9a503273fb
7 changed files with 34 additions and 66 deletions

View file

@ -10,6 +10,9 @@ export const meta = {
requireCredential: false, requireCredential: false,
allowGet: true,
cacheSec: 60,
res: { res: {
type: 'object', type: 'object',
optional: false, nullable: false, optional: false, nullable: false,
@ -253,7 +256,12 @@ export const meta = {
export const paramDef = { export const paramDef = {
type: 'object', type: 'object',
properties: { 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: [], required: [],
} as const; } as const;
@ -276,7 +284,7 @@ export default define(meta, paramDef, async (ps, me) => {
}, },
}); });
const response: any = { return {
maintainerName: instance.maintainerName, maintainerName: instance.maintainerName,
maintainerEmail: instance.maintainerEmail, maintainerEmail: instance.maintainerEmail,
@ -317,21 +325,16 @@ export default define(meta, paramDef, async (ps, me) => {
translatorAvailable: instance.deeplAuthKey != null, translatorAvailable: instance.deeplAuthKey != null,
...(ps.detail ? { pinnedPages: instance.pinnedPages,
pinnedPages: instance.pinnedPages, pinnedClipId: instance.pinnedClipId,
pinnedClipId: instance.pinnedClipId, cacheRemoteFiles: instance.cacheRemoteFiles,
cacheRemoteFiles: instance.cacheRemoteFiles, requireSetup: (await Users.countBy({
requireSetup: (await Users.countBy({ host: IsNull(),
host: IsNull(), })) === 0,
})) === 0,
} : {}),
};
if (ps.detail) { proxyAccountName: instance.proxyAccountId ? (await Users.pack(instance.proxyAccountId).catch(() => null))?.username : null,
const proxyAccount = instance.proxyAccountId ? await Users.pack(instance.proxyAccountId).catch(() => null) : null;
response.proxyAccountName = proxyAccount ? proxyAccount.username : null; features: {
response.features = {
registration: !instance.disableRegistration, registration: !instance.disableRegistration,
localTimeLine: !instance.disableLocalTimeline, localTimeLine: !instance.disableLocalTimeline,
globalTimeLine: !instance.disableGlobalTimeline, globalTimeLine: !instance.disableGlobalTimeline,
@ -345,8 +348,6 @@ export default define(meta, paramDef, async (ps, me) => {
discord: instance.enableDiscordIntegration, discord: instance.enableDiscordIntegration,
serviceWorker: instance.enableServiceWorker, serviceWorker: instance.enableServiceWorker,
miauth: true, miauth: true,
}; },
} };
return response;
}); });

View file

@ -1,17 +1,9 @@
<template> <template>
<div v-if="meta" class="xfbouadm" :style="{ backgroundImage: `url(${ meta.backgroundImageUrl })` }"></div> <div class="xfbouadm" :style="{ backgroundImage: `url(${ instance.backgroundImageUrl })` }"></div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref } from 'vue'; import { instance } from '@/instance';
import * as foundkey from 'foundkey-js';
import * as os from '@/os';
const meta = ref<foundkey.entities.DetailedInstanceMetadata>();
os.api('meta', { detail: true }).then(gotMeta => {
meta.value = gotMeta;
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View file

@ -1,6 +1,6 @@
import { computed, reactive } from 'vue'; import { computed, reactive } from 'vue';
import * as foundkey from 'foundkey-js'; import * as foundkey from 'foundkey-js';
import { api } from '@/os'; import { apiGet } from '@/os';
// TODO: 他のタブと永続化されたstateを同期 // TODO: 他のタブと永続化されたstateを同期
@ -13,13 +13,7 @@ export const instance: foundkey.entities.InstanceMetadata = reactive(instanceDat
}); });
export async function fetchInstance(): Promise<void> { export async function fetchInstance(): Promise<void> {
const meta = await api('meta', { Object.assign(instance, await apiGet('meta'));
detail: false,
});
for (const [k, v] of Object.entries(meta)) {
instance[k] = v;
}
localStorage.setItem('instance', JSON.stringify(instance)); localStorage.setItem('instance', JSON.stringify(instance));
} }

View file

@ -4,7 +4,7 @@
<div v-show="loaded" class="mjndxjch"> <div v-show="loaded" class="mjndxjch">
<img src="https://xn--931a.moe/assets/error.jpg" class="_ghost"/> <img src="https://xn--931a.moe/assets/error.jpg" class="_ghost"/>
<p><b><i class="fas fa-exclamation-triangle"></i> {{ i18n.ts.pageLoadError }}</b></p> <p><b><i class="fas fa-exclamation-triangle"></i> {{ i18n.ts.pageLoadError }}</b></p>
<p v-if="meta && (version === meta.version)">{{ i18n.ts.pageLoadErrorDescription }}</p> <p v-if="version === instance.version">{{ i18n.ts.pageLoadErrorDescription }}</p>
<p v-else-if="serverIsDead">{{ i18n.ts.serverIsDead }}</p> <p v-else-if="serverIsDead">{{ i18n.ts.serverIsDead }}</p>
<template v-else> <template v-else>
<p>{{ i18n.ts.newVersionOfClientAvailable }}</p> <p>{{ i18n.ts.newVersionOfClientAvailable }}</p>
@ -21,6 +21,7 @@
import * as foundkey from 'foundkey-js'; import * as foundkey from 'foundkey-js';
import MkButton from '@/components/ui/button.vue'; import MkButton from '@/components/ui/button.vue';
import { version } from '@/config'; import { version } from '@/config';
import { instance } from '@/instance';
import * as os from '@/os'; import * as os from '@/os';
import { unisonReload } from '@/scripts/unison-reload'; import { unisonReload } from '@/scripts/unison-reload';
import { i18n } from '@/i18n'; import { i18n } from '@/i18n';
@ -34,15 +35,11 @@ withDefaults(defineProps<{
let loaded = $ref(false); let loaded = $ref(false);
let serverIsDead = $ref(false); let serverIsDead = $ref(false);
let meta = $ref<foundkey.entities.LiteInstanceMetadata | null>(null);
os.api('meta', { // just checking whether the server is alive or dead
detail: false, os.api('ping').then(() => {
}).then(res => {
loaded = true; loaded = true;
serverIsDead = false; serverIsDead = false;
meta = res;
localStorage.setItem('v', res.version);
}, () => { }, () => {
loaded = true; loaded = true;
serverIsDead = true; serverIsDead = true;

View file

@ -1,5 +1,5 @@
<template> <template>
<div v-if="meta" class="rsqzvsbo"> <div class="rsqzvsbo">
<div class="top"> <div class="top">
<MkFeaturedPhotos class="bg"/> <MkFeaturedPhotos class="bg"/>
<XTimeline class="tl"/> <XTimeline class="tl"/>
@ -19,12 +19,12 @@
<div class="fg"> <div class="fg">
<h1> <h1>
<!-- 背景色によってはロゴが見えなくなるのでとりあえず無効に --> <!-- 背景色によってはロゴが見えなくなるのでとりあえず無効に -->
<!-- <img class="logo" v-if="meta.logoImageUrl" :src="meta.logoImageUrl"><span v-else class="text">{{ instanceName }}</span> --> <!-- <img class="logo" v-if="instance.logoImageUrl" :src="instance.logoImageUrl"><span v-else class="text">{{ instanceName }}</span> -->
<span class="text">{{ instanceName }}</span> <span class="text">{{ instanceName }}</span>
</h1> </h1>
<div class="about"> <div class="about">
<!-- eslint-disable-next-line vue/no-v-html --> <!-- eslint-disable-next-line vue/no-v-html -->
<div class="desc" v-html="meta.description || i18n.ts.headlineMisskey"></div> <div class="desc" v-html="instance.description || i18n.ts.headlineMisskey"></div>
</div> </div>
<div class="action"> <div class="action">
<MkButton inline rounded gradate data-cy-signup style="margin-right: 12px;" @click="signup()">{{ i18n.ts.signup }}</MkButton> <MkButton inline rounded gradate data-cy-signup style="margin-right: 12px;" @click="signup()">{{ i18n.ts.signup }}</MkButton>
@ -58,17 +58,13 @@ import { host, instanceName } from '@/config';
import * as os from '@/os'; import * as os from '@/os';
import number from '@/filters/number'; import number from '@/filters/number';
import { i18n } from '@/i18n'; import { i18n } from '@/i18n';
import { instance } from '@/instance';
let meta = $ref();
let stats = $ref(); let stats = $ref();
let tags = $ref(); let tags = $ref();
let onlineUsersCount = $ref(); let onlineUsersCount = $ref();
let instances = $ref(); let instances = $ref();
os.api('meta', { detail: true }).then(_meta => {
meta = _meta;
});
os.api('stats').then(_stats => { os.api('stats').then(_stats => {
stats = _stats; stats = _stats;
}); });

View file

@ -1,8 +1,6 @@
<template> <template>
<div v-if="meta"> <XSetup v-if="instance.requireSetup"/>
<XSetup v-if="meta.requireSetup"/>
<XEntrance v-else/> <XEntrance v-else/>
</div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
@ -10,15 +8,10 @@ import { computed } from 'vue';
import XSetup from './welcome.setup.vue'; import XSetup from './welcome.setup.vue';
import XEntrance from './welcome.entrance.a.vue'; import XEntrance from './welcome.entrance.a.vue';
import { instanceName } from '@/config'; import { instanceName } from '@/config';
import { instance } from '@/instance';
import * as os from '@/os'; import * as os from '@/os';
import { definePageMetadata } from '@/scripts/page-metadata'; import { definePageMetadata } from '@/scripts/page-metadata';
let meta = $ref(null);
os.api('meta', { detail: true }).then(res => {
meta = res;
});
definePageMetadata(computed(() => ({ definePageMetadata(computed(() => ({
title: instanceName, title: instanceName,
icon: null, icon: null,

View file

@ -80,7 +80,6 @@ const announcements = {
let showMenu = $ref(false); let showMenu = $ref(false);
let isDesktop = $ref(window.innerWidth >= DESKTOP_THRESHOLD); let isDesktop = $ref(window.innerWidth >= DESKTOP_THRESHOLD);
let narrow = $ref(window.innerWidth < 1280); let narrow = $ref(window.innerWidth < 1280);
let meta = $ref();
const keymap = $computed(() => { const keymap = $computed(() => {
return { return {
@ -94,10 +93,6 @@ const keymap = $computed(() => {
const root = $computed(() => mainRouter.currentRoute.value.name === 'index'); const root = $computed(() => mainRouter.currentRoute.value.name === 'index');
os.api('meta', { detail: true }).then(res => {
meta = res;
});
function signin() { function signin() {
os.popup(XSigninDialog, { os.popup(XSigninDialog, {
autoSet: true, autoSet: true,