mirror of https://github.com/certd/certd
chore:
parent
f8f3e8b43f
commit
b09acfb4dc
|
@ -1,5 +1,6 @@
|
||||||
import { Registrable } from "../registry/index.js";
|
import { Registrable } from "../registry/index.js";
|
||||||
import { FormItemProps } from "../dt/index.js";
|
import { FormItemProps } from "../dt/index.js";
|
||||||
|
import { HttpClient, ILogger, utils } from "../utils";
|
||||||
|
|
||||||
export type AccessInputDefine = FormItemProps & {
|
export type AccessInputDefine = FormItemProps & {
|
||||||
title: string;
|
title: string;
|
||||||
|
@ -15,5 +16,13 @@ export interface IAccessService {
|
||||||
getById<T = any>(id: any): Promise<T>;
|
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
|
// 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 { Decorator } from "../decorator/index.js";
|
||||||
import _ from "lodash-es";
|
import _ from "lodash-es";
|
||||||
import { accessRegistry } from "./registry.js";
|
import { accessRegistry } from "./registry.js";
|
||||||
|
import { http, logger, utils } from "../utils";
|
||||||
|
|
||||||
// 提供一个唯一 key
|
// 提供一个唯一 key
|
||||||
export const ACCESS_CLASS_KEY = "pipeline:access";
|
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);
|
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;
|
title?: string;
|
||||||
access: T;
|
access: T;
|
||||||
};
|
};
|
||||||
export type AccessRequestHandleReq<T = any> = PluginRequestHandleReq<AccessRequestHandleReqInput<T>>;
|
|
||||||
|
|
||||||
export type AccessRequestHandleContext = {
|
export type AccessRequestHandleContext = {
|
||||||
http: HttpClient;
|
http: HttpClient;
|
||||||
logger: ILogger;
|
logger: ILogger;
|
||||||
utils: typeof utils;
|
utils: typeof utils;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type AccessRequestHandleReq<T = any> = PluginRequestHandleReq<AccessRequestHandleReqInput<T>>;
|
||||||
|
|
||||||
export class AccessRequestHandler<T = any> {
|
export class AccessRequestHandler<T = any> {
|
||||||
async onRequest(req: AccessRequestHandleReq<T>, ctx: AccessRequestHandleContext) {
|
async onRequest(req: AccessRequestHandleReq<T>, ctx: AccessRequestHandleContext) {
|
||||||
if (!req.action) {
|
if (!req.action) {
|
||||||
|
|
|
@ -42,6 +42,7 @@ async function getDeviceId() {
|
||||||
|
|
||||||
modal.confirm({
|
modal.confirm({
|
||||||
title: "请输入OTP验证码",
|
title: "请输入OTP验证码",
|
||||||
|
maskClosable: true,
|
||||||
content: () => {
|
content: () => {
|
||||||
return (
|
return (
|
||||||
<a-form-item-rest>
|
<a-form-item-rest>
|
||||||
|
|
|
@ -135,6 +135,7 @@ function openUpgrade() {
|
||||||
async onOk() {
|
async onOk() {
|
||||||
return await doActive();
|
return await doActive();
|
||||||
},
|
},
|
||||||
|
maskClosable: true,
|
||||||
okText: "激活",
|
okText: "激活",
|
||||||
width: 500,
|
width: 500,
|
||||||
content: () => {
|
content: () => {
|
||||||
|
|
|
@ -130,7 +130,7 @@ export const useUserStore = defineStore({
|
||||||
*/
|
*/
|
||||||
confirmLoginOut() {
|
confirmLoginOut() {
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
Modal.config({
|
Modal.confirm({
|
||||||
iconType: "warning",
|
iconType: "warning",
|
||||||
title: t("app.login.logoutTip"),
|
title: t("app.login.logoutTip"),
|
||||||
content: t("app.login.logoutMessage"),
|
content: t("app.login.logoutMessage"),
|
||||||
|
|
|
@ -235,6 +235,7 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp
|
||||||
const files = await api.GetFiles(row.id);
|
const files = await api.GetFiles(row.id);
|
||||||
Modal.success({
|
Modal.success({
|
||||||
title: "文件下载",
|
title: "文件下载",
|
||||||
|
maskClosable: true,
|
||||||
okText: "↑↑↑ 点击上面链接下载",
|
okText: "↑↑↑ 点击上面链接下载",
|
||||||
content: () => {
|
content: () => {
|
||||||
const children = [];
|
const children = [];
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||||
import { Constants } from '../../../basic/constants.js';
|
import { Constants } from '../../../basic/constants.js';
|
||||||
import {
|
import {
|
||||||
accessRegistry,
|
|
||||||
AccessRequestHandleContext,
|
|
||||||
AccessRequestHandleReq,
|
AccessRequestHandleReq,
|
||||||
http,
|
http,
|
||||||
ITaskPlugin,
|
ITaskPlugin,
|
||||||
logger,
|
logger,
|
||||||
mergeUtils,
|
mergeUtils,
|
||||||
|
newAccess,
|
||||||
pluginRegistry,
|
pluginRegistry,
|
||||||
PluginRequestHandleReq,
|
PluginRequestHandleReq,
|
||||||
TaskInstanceContext,
|
TaskInstanceContext,
|
||||||
|
@ -28,15 +27,6 @@ export class HandleController extends BaseController {
|
||||||
|
|
||||||
@Post('/access', { summary: Constants.per.authOnly })
|
@Post('/access', { summary: Constants.per.authOnly })
|
||||||
async accessRequest(@Body(ALL) body: AccessRequestHandleReq) {
|
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;
|
let inputAccess = body.input.access;
|
||||||
if (body.input.id > 0) {
|
if (body.input.id > 0) {
|
||||||
const oldEntity = await this.accessService.info(body.input.id);
|
const oldEntity = await this.accessService.info(body.input.id);
|
||||||
|
@ -49,14 +39,10 @@ export class HandleController extends BaseController {
|
||||||
inputAccess = this.accessService.decryptAccessEntity(param);
|
inputAccess = this.accessService.decryptAccessEntity(param);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mergeUtils.merge(access, inputAccess);
|
|
||||||
|
|
||||||
const ctx: AccessRequestHandleContext = {
|
const access = newAccess(body.typeName, inputAccess);
|
||||||
http: http,
|
|
||||||
logger: logger,
|
const res = await access.onRequest(body);
|
||||||
utils,
|
|
||||||
};
|
|
||||||
const res = await access.onRequest(body, ctx);
|
|
||||||
|
|
||||||
return this.ok(res);
|
return this.ok(res);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import { BaseService } from '../../../basic/base-service.js';
|
import { BaseService } from '../../../basic/base-service.js';
|
||||||
import { AccessEntity } from '../entity/access.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 { EncryptService } from './encrypt-service.js';
|
||||||
import { ValidateException } from '../../../basic/exception/validation-exception.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 access = accessRegistry.get(entity.type);
|
||||||
const setting = this.decryptAccessEntity(entity);
|
const setting = this.decryptAccessEntity(entity);
|
||||||
return {
|
const input = {
|
||||||
id: entity.id,
|
id: entity.id,
|
||||||
...setting,
|
...setting,
|
||||||
};
|
};
|
||||||
|
return newAccess(entity.type, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
decryptAccessEntity(entity: AccessEntity): any {
|
decryptAccessEntity(entity: AccessEntity): any {
|
||||||
|
|
Loading…
Reference in New Issue