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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core'; import {ALL, Body, Controller, Inject, Post, Provide} from '@midwayjs/core';
import { BaseController, Constants } from '@certd/lib-server'; import {AccessGetter, AccessService, BaseController, Constants} from '@certd/lib-server';
import { import {
AccessRequestHandleReq, AccessRequestHandleReq,
ITaskPlugin, ITaskPlugin,
@ -10,10 +10,10 @@ import {
PluginRequestHandleReq, PluginRequestHandleReq,
TaskInstanceContext, TaskInstanceContext,
} from '@certd/pipeline'; } from '@certd/pipeline';
import { AccessService, AccessGetter } from '@certd/lib-server'; import {EmailService} from '../../../modules/basic/service/email-service.js';
import { EmailService } from '../../../modules/basic/service/email-service.js'; import {http, HttpRequestConfig, logger, mergeUtils, utils} from '@certd/basic';
import { http, HttpRequestConfig, logger, mergeUtils, utils } from '@certd/basic'; import {NotificationService} from '../../../modules/pipeline/service/notification-service.js';
import { NotificationService } from '../../../modules/pipeline/service/notification-service.js'; import {CertApplyUploadService} from "../../../modules/pipeline/service/cert-apply-upload-service.js";
@Provide() @Provide()
@Controller('/api/pi/handle') @Controller('/api/pi/handle')
@ -24,6 +24,9 @@ export class HandleController extends BaseController {
@Inject() @Inject()
emailService: EmailService; emailService: EmailService;
@Inject()
certApplyUploadService: CertApplyUploadService;
@Inject() @Inject()
notificationService: NotificationService; notificationService: NotificationService;
@ -92,6 +95,15 @@ export class HandleController extends BaseController {
savePath, savePath,
}); });
}; };
const serviceContainer:any = {
CertApplyUploadService:this.certApplyUploadService
}
const serviceGetter = {
get:(name: string) => {
return serviceContainer[name]
}
}
//@ts-ignore //@ts-ignore
const taskCtx: TaskInstanceContext = { const taskCtx: TaskInstanceContext = {
pipeline: undefined, pipeline: undefined,
@ -107,6 +119,7 @@ export class HandleController extends BaseController {
userContext: undefined, userContext: undefined,
fileStore: undefined, fileStore: undefined,
signal: undefined, signal: undefined,
user: {id:userId,role:"user"},
// pipelineContext: this.pipelineContext, // pipelineContext: this.pipelineContext,
// userContext: this.contextFactory.getContext('user', this.options.userId), // userContext: this.contextFactory.getContext('user', this.options.userId),
// fileStore: new FileStore({ // fileStore: new FileStore({
@ -116,6 +129,7 @@ export class HandleController extends BaseController {
// }), // }),
// signal: this.abort.signal, // signal: this.abort.signal,
utils, utils,
serviceGetter
}; };
instance.setCtx(taskCtx); instance.setCtx(taskCtx);
mergeUtils.merge(plugin, body.input); 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 { NotificationGetter } from "./notification-getter.js";
import { UserSuiteEntity, UserSuiteService } from "@certd/commercial-core"; import { UserSuiteEntity, UserSuiteService } from "@certd/commercial-core";
import { CertInfoService } from "../../monitor/service/cert-info-service.js"; 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(); const runningTasks: Map<string | number, Executor> = new Map();
@ -92,6 +93,8 @@ export class PipelineService extends BaseService<PipelineEntity> {
@Inject() @Inject()
certInfoService: CertInfoService; certInfoService: CertInfoService;
@Inject()
certApplyUploadService: CertApplyUploadService;
//@ts-ignore //@ts-ignore
getRepository() { getRepository() {
return this.repository; return this.repository;
@ -481,7 +484,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
sysInfo.title = siteInfo.title; sysInfo.title = siteInfo.title;
} }
const serviceContainer = { const serviceContainer = {
CertInfoService: this.certInfoService CertApplyUploadService: this.certApplyUploadService
} }
const serviceGetter = { const serviceGetter = {
get:(name: string) => { get:(name: string) => {