From 5f82117c527b0af912c15729d0108154c1849ee7 Mon Sep 17 00:00:00 2001 From: wibus-wee <1596355173@qq.com> Date: Sat, 1 Apr 2023 23:12:56 +0800 Subject: [PATCH] fix(themes): active multi-themes --- apps/core/src/bootstrap.ts | 3 ++- apps/core/src/modules/themes/themes.controller.ts | 2 +- apps/themes-service/src/themes-service.service.ts | 10 +++------- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/apps/core/src/bootstrap.ts b/apps/core/src/bootstrap.ts index a0ca81ebc..cec3781fd 100644 --- a/apps/core/src/bootstrap.ts +++ b/apps/core/src/bootstrap.ts @@ -103,8 +103,9 @@ export async function bootstrap() { consola.success( `[${prefix + pid}] 服务器正在监听: ${listening_ip}:${PORT}`, ); + consola.success(`Mog Core 已启动. ${chalk.yellow(`+${performance.now() | 0}ms`)}`); Logger.log( - `NxServer 已启动. ${chalk.yellow(`+${performance.now() | 0}ms`)}`, + `Mog Core 已启动. ${chalk.yellow(`+${performance.now() | 0}ms`)}`, ); }); if (module.hot) { diff --git a/apps/core/src/modules/themes/themes.controller.ts b/apps/core/src/modules/themes/themes.controller.ts index 7ade3512d..8a318130c 100644 --- a/apps/core/src/modules/themes/themes.controller.ts +++ b/apps/core/src/modules/themes/themes.controller.ts @@ -50,7 +50,7 @@ export class ThemesController { }); } - @Patch('/:id') + @Get('/:id/active') @Auth() @ApiOperation({ summary: '激活主题' }) async active(@Param('id') id: string) { diff --git a/apps/themes-service/src/themes-service.service.ts b/apps/themes-service/src/themes-service.service.ts index 11f20ede3..d2b5b3614 100644 --- a/apps/themes-service/src/themes-service.service.ts +++ b/apps/themes-service/src/themes-service.service.ts @@ -336,13 +336,9 @@ export class ThemesServiceService { } _theme.active = true; if (!theme) { - await this.configService.patchAndValidate('seo', { - ...(await this.configService.get('seo')), - }); - await this.configService.patchAndValidate('themes', [ ...themes.filter((t) => t.id !== activeTheme?.id), - ...(activeTheme ? [activeTheme] : []), + (activeTheme ? activeTheme : undefined), _theme, ]); return true; @@ -352,11 +348,11 @@ export class ThemesServiceService { ...themes .filter((t) => t.id !== id) .filter((t) => t.id !== activeTheme?.id), + (activeTheme ? activeTheme : undefined), _theme, // 重新获取一次, 防止配置文件被修改而无更新 ]); this.setENV(_theme.path); - this.untrackThemeChange(); // 取消旧主题的监听 - this.trackThemeChange(); // 监听新主题的变化 + this.refreshThemes(); activeTheme && this.notificationService.emit(ThemesEvents.ThemeAfterDeactivate, {