From eceaa88268b2ef8b91b170ab82fc5b2e9faea4bf Mon Sep 17 00:00:00 2001 From: Sceuick Date: Fri, 30 Jun 2023 00:48:25 +0800 Subject: [PATCH] Fix maint mode --- common/types/schema.ts | 3 +++ srv/api/user/settings.ts | 10 +++++++--- srv/db/user.ts | 4 ++-- web/store/settings.ts | 7 ++++++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/common/types/schema.ts b/common/types/schema.ts index 4c8206deb..04aac6494 100644 --- a/common/types/schema.ts +++ b/common/types/schema.ts @@ -60,6 +60,9 @@ export namespace AppSchema { export interface User { _id: string + + updatedAt?: string + kind: 'user' username: string hash: string diff --git a/srv/api/user/settings.ts b/srv/api/user/settings.ts index 7dbd81eb8..edcd33b0d 100644 --- a/srv/api/user/settings.ts +++ b/srv/api/user/settings.ts @@ -19,15 +19,19 @@ import { UI } from '/common/types' import { publishOne } from '../ws/handle' export const getInitialLoad = handle(async ({ userId }) => { - const [profile, user, presets, config, books] = await Promise.all([ + const appConfig = await getAppConfig() + if (config.ui.maintenance) { + return { config: appConfig } + } + + const [profile, user, presets, books] = await Promise.all([ store.users.getProfile(userId!), getSafeUserConfig(userId!), store.presets.getUserPresets(userId!), - getAppConfig(), store.memory.getBooks(userId!), ]) - return { profile, user, presets, config, books } + return { profile, user, presets, config: appConfig, books } }) export const getProfile = handle(async ({ userId, params }) => { diff --git a/srv/db/user.ts b/srv/db/user.ts index 5a394bffd..0894160c4 100644 --- a/srv/db/user.ts +++ b/srv/db/user.ts @@ -53,11 +53,11 @@ export async function updateUserUI(userId: string, props: Partial) { - await db('user').updateOne({ userId }, { $set: props }) + await db('user').updateOne({ userId }, { $set: { ...props, updatedAt: now() } }) return getUser(userId) } diff --git a/web/store/settings.ts b/web/store/settings.ts index ec091a86e..39d1382d9 100644 --- a/web/store/settings.ts +++ b/web/store/settings.ts @@ -76,7 +76,12 @@ export const settingStore = createStore( if (res.result) { setAssetPrefix(res.result.config.assetPrefix) - events.emit(EVENTS.init, res.result) + + const isMaint = res.result.config?.maintenance + if (!isMaint) { + events.emit(EVENTS.init, res.result) + } + yield { init: res.result, config: res.result.config } const maint = res.result.config?.maintenance