pull/361/head
xiaojunnuo 2025-03-21 12:23:59 +08:00
parent 1e6ddd250e
commit 656cb89fe8
7 changed files with 92 additions and 21 deletions

View File

@ -0,0 +1,6 @@
import { CertInfo } from "../acme";
export interface ICertApplyUploadService {
getCertInfo: (opts: { certId: number; userId: number }) => Promise<any>;
updateCert: (opts: { certId: number; cert: CertInfo; userId: number }) => Promise<any>;
}

View File

@ -2,11 +2,12 @@ import { IsTaskPlugin, pluginGroups, RunStrategy, Step, TaskInput, TaskOutput }
import type { CertInfo } from "../acme.js";
import { CertReader } from "../cert-reader.js";
import { CertApplyBaseConvertPlugin } from "../base-convert.js";
import dayjs from "dayjs";
export * from "./d.js";
import dayjs from "dayjs";
import { ICertApplyUploadService } from "./d";
export { CertReader };
export type { CertInfo };
@IsTaskPlugin({
name: "CertApplyUpload",
icon: "ph:certificate",
@ -20,20 +21,21 @@ export type { CertInfo };
},
shortcut: {
certUpdate: {
title: "上传证书",
title: "更新证书",
icon: "ph:upload",
action: "onCertUpdate",
form: {
columns: {
crt: {
title: "证书",
type: "textarea",
type: "text",
form: {
component: {
name: "pem-input",
vModel: "modelValue",
textarea: {
row: 4,
rows: 4,
placeholder: "-----BEGIN CERTIFICATE-----\n...\n...\n-----END CERTIFICATE-----",
},
},
rules: [{ required: true, message: "此项必填" }],
@ -42,13 +44,14 @@ export type { CertInfo };
},
key: {
title: "私钥",
type: "textarea",
type: "text",
form: {
component: {
name: "pem-input",
vModel: "modelValue",
textarea: {
row: 4,
rows: 4,
placeholder: "-----BEGIN PRIVATE KEY-----\n...\n...\n-----END PRIVATE KEY----- ",
},
},
rules: [{ required: true, message: "此项必填" }],
@ -67,6 +70,7 @@ export class CertApplyUploadPlugin extends CertApplyBaseConvertPlugin {
name: "cert-info-selector",
vModel: "modelValue",
},
helper: "请不要随意修改",
order: -9999,
required: true,
mergeScript: `
@ -98,10 +102,10 @@ export class CertApplyUploadPlugin extends CertApplyBaseConvertPlugin {
async onInit(): Promise<void> {}
async getCertFromStore() {
const siteInfoService = await this.ctx.serviceGetter.get("CertInfoService");
const certApplyUploadService: ICertApplyUploadService = await this.ctx.serviceGetter.get("CertApplyUploadService");
const certInfo = await siteInfoService.getCertInfo({
certId: this.certInfoId,
const certInfo = await certApplyUploadService.getCertInfo({
certId: Number(this.certInfoId),
userId: this.pipeline.userId,
});
@ -137,7 +141,18 @@ export class CertApplyUploadPlugin extends CertApplyBaseConvertPlugin {
return;
}
async onCertUpdate(data: any) {}
async onCertUpdate(data: any) {
const certApplyUploadService = await this.ctx.serviceGetter.get("CertApplyUploadService");
await certApplyUploadService.updateCert({
certId: this.certInfoId,
userId: this.ctx.user.id,
cert: {
crt: data.crt,
key: data.key,
},
});
}
}
new CertApplyUploadPlugin();

View File

@ -1,6 +1,6 @@
<template>
<div class="pem-selector">
<file-input v-bind="fileInput" class="mb-5" type="primary" text="选择文件" @change="onChange" />
<div class="pem-input">
<FileInput v-bind="fileInput" class="mb-5" type="primary" text="选择文件" @change="onChange" />
<a-textarea v-bind="textarea" v-model:value="textRef"></a-textarea>
</div>
</template>
@ -8,6 +8,7 @@
<script setup lang="ts">
import { notification } from "ant-design-vue";
import { ref, watch, defineEmits } from "vue";
import FileInput from "/@/components/file-input.vue";
const props = defineProps<{
modelValue?: string;
@ -51,7 +52,7 @@ watch(
</script>
<style lang="less">
.pem-selector {
.pem-input {
display: flex;
flex-direction: column;
gap: 5px;

View File

@ -9,6 +9,7 @@
import { doRequest } from "/@/components/plugins/lib";
import { ref, useAttrs } from "vue";
import { useFormWrapper } from "@fast-crud/fast-crud";
import { notification } from "ant-design-vue";
defineOptions({
name: "TaskShortcut",
@ -37,6 +38,9 @@ async function openDialog() {
title: props.title,
saveRemind: false,
},
afterSubmit() {
notification.success({ message: "操作成功" });
},
async doSubmit({ form }: any) {
return await doPluginFormSubmit(form);
},

View File

@ -1,5 +1,5 @@
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
import { BaseController, Constants } from '@certd/lib-server';
import {ALL, Body, Controller, Inject, Post, Provide} from '@midwayjs/core';
import {AccessGetter, AccessService, BaseController, Constants} from '@certd/lib-server';
import {
AccessRequestHandleReq,
ITaskPlugin,
@ -10,10 +10,10 @@ import {
PluginRequestHandleReq,
TaskInstanceContext,
} from '@certd/pipeline';
import { AccessService, AccessGetter } from '@certd/lib-server';
import { EmailService } from '../../../modules/basic/service/email-service.js';
import { http, HttpRequestConfig, logger, mergeUtils, utils } from '@certd/basic';
import { NotificationService } from '../../../modules/pipeline/service/notification-service.js';
import {EmailService} from '../../../modules/basic/service/email-service.js';
import {http, HttpRequestConfig, logger, mergeUtils, utils} from '@certd/basic';
import {NotificationService} from '../../../modules/pipeline/service/notification-service.js';
import {CertApplyUploadService} from "../../../modules/pipeline/service/cert-apply-upload-service.js";
@Provide()
@Controller('/api/pi/handle')
@ -24,6 +24,9 @@ export class HandleController extends BaseController {
@Inject()
emailService: EmailService;
@Inject()
certApplyUploadService: CertApplyUploadService;
@Inject()
notificationService: NotificationService;
@ -92,6 +95,15 @@ export class HandleController extends BaseController {
savePath,
});
};
const serviceContainer:any = {
CertApplyUploadService:this.certApplyUploadService
}
const serviceGetter = {
get:(name: string) => {
return serviceContainer[name]
}
}
//@ts-ignore
const taskCtx: TaskInstanceContext = {
pipeline: undefined,
@ -107,6 +119,7 @@ export class HandleController extends BaseController {
userContext: undefined,
fileStore: undefined,
signal: undefined,
user: {id:userId,role:"user"},
// pipelineContext: this.pipelineContext,
// userContext: this.contextFactory.getContext('user', this.options.userId),
// fileStore: new FileStore({
@ -116,6 +129,7 @@ export class HandleController extends BaseController {
// }),
// signal: this.abort.signal,
utils,
serviceGetter
};
instance.setCtx(taskCtx);
mergeUtils.merge(plugin, body.input);

View File

@ -0,0 +1,28 @@
import {ICertApplyUploadService} from "@certd/plugin-cert";
import {IMidwayContext, Inject, Provide} from "@midwayjs/core";
import {CertInfoService} from "../../monitor/index.js";
import {CertUploadService} from "../../monitor/service/cert-upload-service.js";
@Provide("CertApplyUploadService")
export class CertApplyUploadService implements ICertApplyUploadService {
@Inject()
ctx : IMidwayContext
async getCertInfo(opts: { certId: number; userId: number; }) {
const certInfoService = this.ctx.getApp().getApplicationContext().get<CertInfoService>("CertInfoService")
const { certId, userId } = opts;
return await certInfoService.getCertInfo({
certId,
userId: Number(userId),
});
};
async updateCert(opts: { certId: any; userId: any; cert: any; }){
const certUploadService = this.ctx.getApp().getApplicationContext().get<CertUploadService>("CertUploadService")
return await certUploadService.updateCert({
id:opts.certId,
userId:opts.userId,
cert:opts.cert
});
}
}

View File

@ -36,6 +36,7 @@ import { NotificationService } from "./notification-service.js";
import { NotificationGetter } from "./notification-getter.js";
import { UserSuiteEntity, UserSuiteService } from "@certd/commercial-core";
import { CertInfoService } from "../../monitor/service/cert-info-service.js";
import {CertApplyUploadService} from "./cert-apply-upload-service.js";
const runningTasks: Map<string | number, Executor> = new Map();
@ -92,6 +93,8 @@ export class PipelineService extends BaseService<PipelineEntity> {
@Inject()
certInfoService: CertInfoService;
@Inject()
certApplyUploadService: CertApplyUploadService;
//@ts-ignore
getRepository() {
return this.repository;
@ -481,7 +484,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
sysInfo.title = siteInfo.title;
}
const serviceContainer = {
CertInfoService: this.certInfoService
CertApplyUploadService: this.certApplyUploadService
}
const serviceGetter = {
get:(name: string) => {