mirror of https://github.com/certd/certd
chore:
parent
f8f3e8b43f
commit
b09acfb4dc
|
@ -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<T = any>(id: any): Promise<T>;
|
||||
}
|
||||
|
||||
// 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;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -13,14 +13,14 @@ export type AccessRequestHandleReqInput<T = any> = {
|
|||
title?: string;
|
||||
access: T;
|
||||
};
|
||||
export type AccessRequestHandleReq<T = any> = PluginRequestHandleReq<AccessRequestHandleReqInput<T>>;
|
||||
|
||||
export type AccessRequestHandleContext = {
|
||||
http: HttpClient;
|
||||
logger: ILogger;
|
||||
utils: typeof utils;
|
||||
};
|
||||
|
||||
export type AccessRequestHandleReq<T = any> = PluginRequestHandleReq<AccessRequestHandleReqInput<T>>;
|
||||
|
||||
export class AccessRequestHandler<T = any> {
|
||||
async onRequest(req: AccessRequestHandleReq<T>, ctx: AccessRequestHandleContext) {
|
||||
if (!req.action) {
|
||||
|
|
|
@ -42,6 +42,7 @@ async function getDeviceId() {
|
|||
|
||||
modal.confirm({
|
||||
title: "请输入OTP验证码",
|
||||
maskClosable: true,
|
||||
content: () => {
|
||||
return (
|
||||
<a-form-item-rest>
|
||||
|
|
|
@ -135,6 +135,7 @@ function openUpgrade() {
|
|||
async onOk() {
|
||||
return await doActive();
|
||||
},
|
||||
maskClosable: true,
|
||||
okText: "激活",
|
||||
width: 500,
|
||||
content: () => {
|
||||
|
|
|
@ -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"),
|
||||
|
|
|
@ -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 = [];
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<AccessEntity> 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 {
|
||||
|
|
Loading…
Reference in New Issue