From fe09e75b800ded5ad46fd7d705752f73720c627b Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Sun, 12 Jul 2026 03:10:52 +0800 Subject: [PATCH] =?UTF-8?q?refactor(nginx-proxy-manager):=20=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E7=9B=B4=E6=8E=A5=E5=8A=A8=E6=80=81=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E4=B8=BA=E8=BF=90=E8=A1=8C=E6=97=B6=E4=BE=9D=E8=B5=96=E5=AF=BC?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将插件中直接使用的动态导入改为通过runtimeDepsService统一处理,同时重构导入方式为runtimeImport变量,移除冗余的form-data和otplib直接导入,统一导入逻辑 --- .../modules/mine/service/two-factor-service.ts | 9 ++++++--- .../nginxProxyManager.yaml | 15 +++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/ui/certd-server/src/modules/mine/service/two-factor-service.ts b/packages/ui/certd-server/src/modules/mine/service/two-factor-service.ts index 1e0a7f764..8075afc62 100644 --- a/packages/ui/certd-server/src/modules/mine/service/two-factor-service.ts +++ b/packages/ui/certd-server/src/modules/mine/service/two-factor-service.ts @@ -2,6 +2,7 @@ import { Inject, Provide, Scope, ScopeEnum } from "@midwayjs/core"; import { UserSettingsService } from "./user-settings-service.js"; import { UserTwoFactorSetting } from "./models.js"; import { UserService } from "../../sys/authority/service/user-service.js"; +import { RuntimeDepsService } from "../../runtime-deps/runtime-deps-service.js"; /** * 授权 @@ -13,13 +14,15 @@ export class TwoFactorService { userSettingsService: UserSettingsService; @Inject() userService: UserService; + @Inject() + runtimeDepsService: RuntimeDepsService; async getAuthenticatorQrCode(userId: any) { const setting = await this.getSetting(userId); const authenticatorSetting = setting.authenticator; if (!authenticatorSetting.secret) { - const { authenticator } = await import("otplib"); + const { authenticator } = await this.runtimeDepsService.importRuntime("otplib"); authenticatorSetting.secret = authenticator.generateSecret(); await this.userSettingsService.saveSetting(userId, null, setting); @@ -38,7 +41,7 @@ export class TwoFactorService { async saveAuthenticator(req: { userId: any; verifyCode: any }) { const userId = req.userId; - const { authenticator } = await import("otplib"); + const { authenticator } = await this.runtimeDepsService.importRuntime("otplib"); const setting = await this.getSetting(userId); const authenticatorSetting = setting.authenticator; @@ -77,7 +80,7 @@ export class TwoFactorService { } async verifyAuthenticatorCode(userId: any, verifyCode: string) { - const { authenticator } = await import("otplib"); + const { authenticator } = await this.runtimeDepsService.importRuntime("otplib"); const setting = await this.getSetting(userId); if (!setting.authenticator.enabled) { throw new Error("authenticator 未开启"); diff --git a/packages/ui/certd-server/src/plugins/plugin-nginx-proxy-manager/nginxProxyManager.yaml b/packages/ui/certd-server/src/plugins/plugin-nginx-proxy-manager/nginxProxyManager.yaml index f9398a200..59932d6df 100644 --- a/packages/ui/certd-server/src/plugins/plugin-nginx-proxy-manager/nginxProxyManager.yaml +++ b/packages/ui/certd-server/src/plugins/plugin-nginx-proxy-manager/nginxProxyManager.yaml @@ -57,12 +57,12 @@ input: action: TestRequest helper: 测试登录并拉取代理主机列表。 content: | - const { BaseAccess } = await import("@certd/pipeline"); - const httpsModule = await import("node:https"); - const { URL } = await import("node:url"); - const axiosModule = await import("axios"); - const formDataModule = await import("form-data"); - const { authenticator } = await import("otplib"); + const runtimeImport = import; + const { BaseAccess } = await runtimeImport("@certd/pipeline"); + const httpsModule = await runtimeImport("node:https"); + const { URL } = await runtimeImport("node:url"); + const axiosModule = await runtimeImport("axios"); + const formDataModule = await runtimeImport("form-data"); const https = httpsModule.default ?? httpsModule; const axios = axiosModule.default ?? axiosModule; @@ -114,6 +114,7 @@ content: | class NginxProxyManagerClient { constructor(options) { this.options = options; + this.importFn = options.importFn; this.endpoint = normalizeEndpoint(options.endpoint); this.apiBaseUrl = `${this.endpoint}/api`; this.token = undefined; @@ -267,6 +268,7 @@ content: | let code; try { + const { authenticator } = await this.importFn("otplib"); code = authenticator.generate(this.options.totpSecret); } catch (error) { throw describeError(error, "Generating TOTP code"); @@ -327,6 +329,7 @@ content: | password: this.password, totpSecret: this.totpSecret || undefined, ignoreTls: this.ignoreTls === true, + importFn: this.importRuntime.bind(this), }); }