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,
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,
} : {}),
};
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;
});

View file

@ -1,17 +1,9 @@
<template>
<div v-if="meta" class="xfbouadm" :style="{ backgroundImage: `url(${ meta.backgroundImageUrl })` }"></div>
<div class="xfbouadm" :style="{ backgroundImage: `url(${ instance.backgroundImageUrl })` }"></div>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
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;
});
import { instance } from '@/instance';
</script>
<style lang="scss" scoped>

View file

@ -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<void> {
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));
}

View file

@ -4,7 +4,7 @@
<div v-show="loaded" class="mjndxjch">
<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 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>
<template v-else>
<p>{{ i18n.ts.newVersionOfClientAvailable }}</p>
@ -21,6 +21,7 @@
import * as foundkey from 'foundkey-js';
import MkButton from '@/components/ui/button.vue';
import { version } from '@/config';
import { instance } from '@/instance';
import * as os from '@/os';
import { unisonReload } from '@/scripts/unison-reload';
import { i18n } from '@/i18n';
@ -34,15 +35,11 @@ withDefaults(defineProps<{
let loaded = $ref(false);
let serverIsDead = $ref(false);
let meta = $ref<foundkey.entities.LiteInstanceMetadata | null>(null);
os.api('meta', {
detail: false,
}).then(res => {
// just checking whether the server is alive or dead
os.api('ping').then(() => {
loaded = true;
serverIsDead = false;
meta = res;
localStorage.setItem('v', res.version);
}, () => {
loaded = true;
serverIsDead = true;

View file

@ -1,5 +1,5 @@
<template>
<div v-if="meta" class="rsqzvsbo">
<div class="rsqzvsbo">
<div class="top">
<MkFeaturedPhotos class="bg"/>
<XTimeline class="tl"/>
@ -19,12 +19,12 @@
<div class="fg">
<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>
</h1>
<div class="about">
<!-- 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 class="action">
<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 number from '@/filters/number';
import { i18n } from '@/i18n';
import { instance } from '@/instance';
let meta = $ref();
let stats = $ref();
let tags = $ref();
let onlineUsersCount = $ref();
let instances = $ref();
os.api('meta', { detail: true }).then(_meta => {
meta = _meta;
});
os.api('stats').then(_stats => {
stats = _stats;
});

View file

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

View file

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