From b09acfb4dccbc5953301169a5303668c928edfbb Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Tue, 1 Oct 2024 23:52:44 +0800 Subject: [PATCH] chore: --- packages/core/pipeline/src/access/api.ts | 13 ++++++++-- .../core/pipeline/src/access/decorator.ts | 24 ++++++++++++++++++- packages/core/pipeline/src/core/handler.ts | 4 ++-- .../plugins/synology/device-id-getter.vue | 1 + .../src/components/vip-button/index.vue | 1 + .../ui/certd-client/src/store/modules/user.ts | 2 +- .../src/views/certd/pipeline/crud.tsx | 1 + .../pipeline/controller/handle-controller.ts | 22 ++++------------- .../pipeline/service/access-service.ts | 5 ++-- 9 files changed, 47 insertions(+), 26 deletions(-) diff --git a/packages/core/pipeline/src/access/api.ts b/packages/core/pipeline/src/access/api.ts index 15a5339df..65cc0c720 100644 --- a/packages/core/pipeline/src/access/api.ts +++ b/packages/core/pipeline/src/access/api.ts @@ -1,5 +1,6 @@ import { Registrable } from "../registry/index.js"; import { FormItemProps } from "../dt/index.js"; +import { HttpClient, ILogger, utils } from "../utils"; export type AccessInputDefine = FormItemProps & { title: string; @@ -15,5 +16,13 @@ export interface IAccessService { getById(id: any): Promise; } -// eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface IAccess {} +export interface IAccess { + ctx: AccessContext; + [key: string]: any; +} + +export type AccessContext = { + http: HttpClient; + logger: ILogger; + utils: typeof utils; +}; diff --git a/packages/core/pipeline/src/access/decorator.ts b/packages/core/pipeline/src/access/decorator.ts index b269ab236..d3d2d3109 100644 --- a/packages/core/pipeline/src/access/decorator.ts +++ b/packages/core/pipeline/src/access/decorator.ts @@ -1,8 +1,9 @@ // src/decorator/memoryCache.decorator.ts -import { AccessDefine, AccessInputDefine } from "./api.js"; +import { AccessContext, AccessDefine, AccessInputDefine } from "./api.js"; import { Decorator } from "../decorator/index.js"; import _ from "lodash-es"; import { accessRegistry } from "./registry.js"; +import { http, logger, utils } from "../utils"; // 提供一个唯一 key export const ACCESS_CLASS_KEY = "pipeline:access"; @@ -37,3 +38,24 @@ export function AccessInput(input?: AccessInputDefine): PropertyDecorator { Reflect.defineMetadata(ACCESS_INPUT_KEY, input, target, propertyKey); }; } + +export function newAccess(type: string, input: any, ctx?: AccessContext) { + const register = accessRegistry.get(type); + if (register == null) { + throw new Error(`access ${type} not found`); + } + // @ts-ignore + const access = new register.target(); + for (const key in input) { + access[key] = input[key]; + } + if (!ctx) { + ctx = { + http, + logger, + utils, + }; + } + access.ctx = ctx; + return access; +} diff --git a/packages/core/pipeline/src/core/handler.ts b/packages/core/pipeline/src/core/handler.ts index 77ff241ff..35a62f1fd 100644 --- a/packages/core/pipeline/src/core/handler.ts +++ b/packages/core/pipeline/src/core/handler.ts @@ -13,14 +13,14 @@ export type AccessRequestHandleReqInput = { title?: string; access: T; }; -export type AccessRequestHandleReq = PluginRequestHandleReq>; - export type AccessRequestHandleContext = { http: HttpClient; logger: ILogger; utils: typeof utils; }; +export type AccessRequestHandleReq = PluginRequestHandleReq>; + export class AccessRequestHandler { async onRequest(req: AccessRequestHandleReq, ctx: AccessRequestHandleContext) { if (!req.action) { diff --git a/packages/ui/certd-client/src/components/plugins/synology/device-id-getter.vue b/packages/ui/certd-client/src/components/plugins/synology/device-id-getter.vue index 02128279d..ebbf8636f 100644 --- a/packages/ui/certd-client/src/components/plugins/synology/device-id-getter.vue +++ b/packages/ui/certd-client/src/components/plugins/synology/device-id-getter.vue @@ -42,6 +42,7 @@ async function getDeviceId() { modal.confirm({ title: "请输入OTP验证码", + maskClosable: true, content: () => { return ( diff --git a/packages/ui/certd-client/src/components/vip-button/index.vue b/packages/ui/certd-client/src/components/vip-button/index.vue index 28dfa9231..682b99772 100644 --- a/packages/ui/certd-client/src/components/vip-button/index.vue +++ b/packages/ui/certd-client/src/components/vip-button/index.vue @@ -135,6 +135,7 @@ function openUpgrade() { async onOk() { return await doActive(); }, + maskClosable: true, okText: "激活", width: 500, content: () => { diff --git a/packages/ui/certd-client/src/store/modules/user.ts b/packages/ui/certd-client/src/store/modules/user.ts index 019b78d07..46d14fd20 100644 --- a/packages/ui/certd-client/src/store/modules/user.ts +++ b/packages/ui/certd-client/src/store/modules/user.ts @@ -130,7 +130,7 @@ export const useUserStore = defineStore({ */ confirmLoginOut() { const { t } = useI18n(); - Modal.config({ + Modal.confirm({ iconType: "warning", title: t("app.login.logoutTip"), content: t("app.login.logoutMessage"), diff --git a/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx b/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx index ba0b6bc29..bda7055a2 100644 --- a/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx +++ b/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx @@ -235,6 +235,7 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp const files = await api.GetFiles(row.id); Modal.success({ title: "文件下载", + maskClosable: true, okText: "↑↑↑ 点击上面链接下载", content: () => { const children = []; diff --git a/packages/ui/certd-server/src/modules/pipeline/controller/handle-controller.ts b/packages/ui/certd-server/src/modules/pipeline/controller/handle-controller.ts index 2aff4601f..4a06d5560 100644 --- a/packages/ui/certd-server/src/modules/pipeline/controller/handle-controller.ts +++ b/packages/ui/certd-server/src/modules/pipeline/controller/handle-controller.ts @@ -1,13 +1,12 @@ import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core'; import { Constants } from '../../../basic/constants.js'; import { - accessRegistry, - AccessRequestHandleContext, AccessRequestHandleReq, http, ITaskPlugin, logger, mergeUtils, + newAccess, pluginRegistry, PluginRequestHandleReq, TaskInstanceContext, @@ -28,15 +27,6 @@ export class HandleController extends BaseController { @Post('/access', { summary: Constants.per.authOnly }) async accessRequest(@Body(ALL) body: AccessRequestHandleReq) { - const accessItem = accessRegistry.get(body.typeName); - const accessCls = accessItem.target; - if (accessCls == null) { - throw new Error(`access ${body.typeName} not found`); - } - //实例化access - //@ts-ignore - const access = new accessCls(); - let inputAccess = body.input.access; if (body.input.id > 0) { const oldEntity = await this.accessService.info(body.input.id); @@ -49,14 +39,10 @@ export class HandleController extends BaseController { inputAccess = this.accessService.decryptAccessEntity(param); } } - mergeUtils.merge(access, inputAccess); - const ctx: AccessRequestHandleContext = { - http: http, - logger: logger, - utils, - }; - const res = await access.onRequest(body, ctx); + const access = newAccess(body.typeName, inputAccess); + + const res = await access.onRequest(body); return this.ok(res); } diff --git a/packages/ui/certd-server/src/modules/pipeline/service/access-service.ts b/packages/ui/certd-server/src/modules/pipeline/service/access-service.ts index 7c11a154c..526babcb2 100644 --- a/packages/ui/certd-server/src/modules/pipeline/service/access-service.ts +++ b/packages/ui/certd-server/src/modules/pipeline/service/access-service.ts @@ -3,7 +3,7 @@ import { InjectEntityModel } from '@midwayjs/typeorm'; import { Repository } from 'typeorm'; import { BaseService } from '../../../basic/base-service.js'; import { AccessEntity } from '../entity/access.js'; -import { AccessDefine, accessRegistry, IAccessService } from '@certd/pipeline'; +import { AccessDefine, accessRegistry, IAccessService, newAccess } from '@certd/pipeline'; import { EncryptService } from './encrypt-service.js'; import { ValidateException } from '../../../basic/exception/validation-exception.js'; @@ -109,10 +109,11 @@ export class AccessService extends BaseService implements IAccessS } // const access = accessRegistry.get(entity.type); const setting = this.decryptAccessEntity(entity); - return { + const input = { id: entity.id, ...setting, }; + return newAccess(entity.type, input); } decryptAccessEntity(entity: AccessEntity): any {