fix: 修复启动时报密钥备份不存在的问题

This commit is contained in:
xiaojunnuo
2026-05-11 22:31:11 +08:00
parent 5f88da1985
commit c966896522
3 changed files with 9 additions and 4 deletions
@@ -12,8 +12,7 @@ export class EncryptService {
@Inject() @Inject()
sysSettingService: SysSettingsService; sysSettingService: SysSettingsService;
@Init() async doInit() {
async init() {
const secret: SysSecret = await this.sysSettingService.getSecret(); const secret: SysSecret = await this.sysSettingService.getSecret();
this.encryptor = new Encryptor(secret.encryptSecret); this.encryptor = new Encryptor(secret.encryptSecret);
} }
@@ -9,7 +9,7 @@ import { AutoPrint } from "./auto-print.js";
@Autoload() @Autoload()
@Scope(ScopeEnum.Request, { allowDowngrade: true }) @Scope(ScopeEnum.Request, { allowDowngrade: true })
export class AutoRegister { export class AutoARegister { //这个A是必须,让他排在第一个 进行init,否则会被其他init模块抢先注册导致报错
@Inject() @Inject()
autoInitSite: AutoInitSite; autoInitSite: AutoInitSite;
@@ -1,5 +1,5 @@
import { logger } from '@certd/basic'; import { logger } from '@certd/basic';
import { PlusService, SysInstallInfo, SysPrivateSettings, SysSettingsService } from '@certd/lib-server'; import { EncryptService, PlusService, SysInstallInfo, SysPrivateSettings, SysSettingsService } from '@certd/lib-server';
import { Config, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core'; import { Config, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
import crypto from 'crypto'; import crypto from 'crypto';
import { nanoid } from 'nanoid'; import { nanoid } from 'nanoid';
@@ -22,6 +22,10 @@ export class AutoInitSite {
@Inject() @Inject()
safeService: SafeService; safeService: SafeService;
@Inject()
encryptService: EncryptService;
async init() { async init() {
logger.info('初始化站点开始'); logger.info('初始化站点开始');
await this.startOptimizeDb(); await this.startOptimizeDb();
@@ -50,6 +54,8 @@ export class AutoInitSite {
//加载一次密钥 //加载一次密钥
await this.sysSettingsService.getSecret(); await this.sysSettingsService.getSecret();
//初始化加密服务
await this.encryptService.doInit();
// 授权许可 // 授权许可
try { try {