mirror of https://github.com/certd/certd
fix: 修复复制流水线出现的各种问题
parent
5ade12d700
commit
6314e8d7eb
|
@ -10,11 +10,52 @@ import { env } from "/@/utils/util.env";
|
||||||
import { useUserStore } from "/@/store/modules/user";
|
import { useUserStore } from "/@/store/modules/user";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { useSettingStore } from "/@/store/modules/settings";
|
import { useSettingStore } from "/@/store/modules/settings";
|
||||||
|
import _ from "lodash-es";
|
||||||
|
|
||||||
export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOptionsProps): CreateCrudOptionsRet {
|
export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOptionsProps): CreateCrudOptionsRet {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const lastResRef = ref();
|
const lastResRef = ref();
|
||||||
|
|
||||||
|
function setRunnableIds(pipeline: any) {
|
||||||
|
const idMap: any = {};
|
||||||
|
function createId(oldId: any) {
|
||||||
|
if (oldId == null) {
|
||||||
|
return nanoid();
|
||||||
|
}
|
||||||
|
const newId = nanoid();
|
||||||
|
idMap[oldId] = newId;
|
||||||
|
return newId;
|
||||||
|
}
|
||||||
|
if (pipeline.stages) {
|
||||||
|
for (const stage of pipeline.stages) {
|
||||||
|
stage.id = createId(stage.id);
|
||||||
|
if (stage.tasks) {
|
||||||
|
for (const task of stage.tasks) {
|
||||||
|
task.id = createId(task.id);
|
||||||
|
if (task.steps) {
|
||||||
|
for (const step of task.steps) {
|
||||||
|
step.id = createId(step.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const trigger of pipeline.triggers) {
|
||||||
|
trigger.id = nanoid();
|
||||||
|
}
|
||||||
|
for (const notification of pipeline.notifications) {
|
||||||
|
notification.id = nanoid();
|
||||||
|
}
|
||||||
|
|
||||||
|
let content = JSON.stringify(pipeline);
|
||||||
|
for (const key in idMap) {
|
||||||
|
content = content.replaceAll(key, idMap[key]);
|
||||||
|
}
|
||||||
|
return JSON.parse(content);
|
||||||
|
}
|
||||||
const pageRequest = async (query: UserPageQuery): Promise<UserPageRes> => {
|
const pageRequest = async (query: UserPageQuery): Promise<UserPageRes> => {
|
||||||
return await api.GetList(query);
|
return await api.GetList(query);
|
||||||
};
|
};
|
||||||
|
@ -34,9 +75,16 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp
|
||||||
title: form.title
|
title: form.title
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const content = JSON.parse(form.content);
|
//复制的流水线
|
||||||
content.title = form.title;
|
delete form.status;
|
||||||
form.content = JSON.stringify(content);
|
delete form.lastHistoryTime;
|
||||||
|
delete form.lastVars;
|
||||||
|
delete form.createTime;
|
||||||
|
delete form.id;
|
||||||
|
let pipeline = JSON.parse(form.content);
|
||||||
|
pipeline.title = form.title;
|
||||||
|
pipeline = setRunnableIds(pipeline);
|
||||||
|
form.content = JSON.stringify(pipeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await api.AddObj(form);
|
const res = await api.AddObj(form);
|
||||||
|
@ -48,12 +96,11 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp
|
||||||
// 添加certd pipeline
|
// 添加certd pipeline
|
||||||
const triggers = [];
|
const triggers = [];
|
||||||
if (form.triggerCron) {
|
if (form.triggerCron) {
|
||||||
triggers.push({ id: nanoid(), title: "定时触发", type: "timer", props: { cron: form.triggerCron } });
|
triggers.push({ title: "定时触发", type: "timer", props: { cron: form.triggerCron } });
|
||||||
}
|
}
|
||||||
const notifications = [];
|
const notifications = [];
|
||||||
if (form.emailNotify) {
|
if (form.emailNotify) {
|
||||||
notifications.push({
|
notifications.push({
|
||||||
id: nanoid(),
|
|
||||||
type: "email",
|
type: "email",
|
||||||
when: ["error", "turnToSuccess"],
|
when: ["error", "turnToSuccess"],
|
||||||
options: {
|
options: {
|
||||||
|
@ -61,19 +108,16 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const pipeline = {
|
let pipeline = {
|
||||||
title: form.domains[0] + "证书自动化",
|
title: form.domains[0] + "证书自动化",
|
||||||
stages: [
|
stages: [
|
||||||
{
|
{
|
||||||
id: nanoid(),
|
|
||||||
title: "证书申请阶段",
|
title: "证书申请阶段",
|
||||||
tasks: [
|
tasks: [
|
||||||
{
|
{
|
||||||
id: nanoid(),
|
|
||||||
title: "证书申请任务",
|
title: "证书申请任务",
|
||||||
steps: [
|
steps: [
|
||||||
{
|
{
|
||||||
id: nanoid(),
|
|
||||||
title: "申请证书",
|
title: "申请证书",
|
||||||
input: {
|
input: {
|
||||||
renewDays: 20,
|
renewDays: 20,
|
||||||
|
@ -92,8 +136,10 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp
|
||||||
triggers,
|
triggers,
|
||||||
notifications
|
notifications
|
||||||
};
|
};
|
||||||
|
pipeline = setRunnableIds(pipeline);
|
||||||
|
|
||||||
const id = await api.Save({
|
const id = await api.Save({
|
||||||
|
title: pipeline.title,
|
||||||
content: JSON.stringify(pipeline),
|
content: JSON.stringify(pipeline),
|
||||||
keepHistoryCount: 30
|
keepHistoryCount: 30
|
||||||
});
|
});
|
||||||
|
@ -147,7 +193,8 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp
|
||||||
click: async (context) => {
|
click: async (context) => {
|
||||||
const { ui } = useUi();
|
const { ui } = useUi();
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const row = context[ui.tableColumn.row];
|
let row = context[ui.tableColumn.row];
|
||||||
|
row = _.cloneDeep(row);
|
||||||
row.title = row.title + "_copy";
|
row.title = row.title + "_copy";
|
||||||
await crudExpose.openCopy({
|
await crudExpose.openCopy({
|
||||||
row: row,
|
row: row,
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
<div class="flow-line"></div>
|
<div class="flow-line"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="task">
|
<div class="task">
|
||||||
<a-button shape="round" type="primary" @click="run">
|
<a-button shape="round" type="primary" @click="run()">
|
||||||
<fs-icon icon="ion:play"></fs-icon>
|
<fs-icon icon="ion:play"></fs-icon>
|
||||||
手动触发
|
手动触发
|
||||||
</a-button>
|
</a-button>
|
||||||
|
@ -231,7 +231,6 @@ import PiTaskView from "./component/task-view/index.vue";
|
||||||
import PiStatusShow from "./component/status-show.vue";
|
import PiStatusShow from "./component/status-show.vue";
|
||||||
import _ from "lodash-es";
|
import _ from "lodash-es";
|
||||||
import { message, Modal, notification } from "ant-design-vue";
|
import { message, Modal, notification } from "ant-design-vue";
|
||||||
import { pluginManager } from "/@/views/certd/pipeline/pipeline/plugin";
|
|
||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
import { PipelineDetail, PipelineOptions, PluginGroups, RunHistory } from "./type";
|
import { PipelineDetail, PipelineOptions, PluginGroups, RunHistory } from "./type";
|
||||||
import type { Runnable } from "@certd/pipeline";
|
import type { Runnable } from "@certd/pipeline";
|
||||||
|
|
|
@ -49,13 +49,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async add(bean: PipelineEntity) {
|
async add(bean: PipelineEntity) {
|
||||||
if (!isPlus()) {
|
await this.save(bean);
|
||||||
const count = await this.repository.count();
|
|
||||||
if (count >= freeCount) {
|
|
||||||
throw new NeedVIPException('免费版最多只能创建10个pipeline');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await super.add(bean);
|
|
||||||
return bean;
|
return bean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,19 +99,37 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async save(bean: PipelineEntity) {
|
async save(bean: PipelineEntity) {
|
||||||
|
let old = null;
|
||||||
|
if (bean.id > 0) {
|
||||||
|
//修改
|
||||||
|
old = await this.info(bean.id);
|
||||||
|
}
|
||||||
|
const isUpdate = bean.id > 0 && old != null;
|
||||||
if (!isPlus()) {
|
if (!isPlus()) {
|
||||||
const count = await this.repository.count();
|
let count = await this.repository.count();
|
||||||
|
if (isUpdate) {
|
||||||
|
count -= 1;
|
||||||
|
}
|
||||||
if (count >= freeCount) {
|
if (count >= freeCount) {
|
||||||
throw new NeedVIPException('免费版最多只能创建10个pipeline');
|
throw new NeedVIPException('免费版最多只能创建10个pipeline');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!isUpdate) {
|
||||||
|
//如果是添加,先保存一下,获取到id,更新pipeline.id
|
||||||
|
await this.addOrUpdate(bean);
|
||||||
|
}
|
||||||
await this.clearTriggers(bean.id);
|
await this.clearTriggers(bean.id);
|
||||||
if (bean.content) {
|
if (bean.content) {
|
||||||
const pipeline = JSON.parse(bean.content);
|
const pipeline = JSON.parse(bean.content);
|
||||||
bean.title = pipeline.title;
|
if (pipeline.title) {
|
||||||
|
bean.title = pipeline.title;
|
||||||
|
}
|
||||||
|
pipeline.id = bean.id;
|
||||||
|
bean.content = JSON.stringify(pipeline);
|
||||||
}
|
}
|
||||||
await this.addOrUpdate(bean);
|
await this.addOrUpdate(bean);
|
||||||
await this.registerTriggerById(bean.id);
|
await this.registerTriggerById(bean.id);
|
||||||
|
return bean;
|
||||||
}
|
}
|
||||||
|
|
||||||
async foreachPipeline(callback: (pipeline: PipelineEntity) => void) {
|
async foreachPipeline(callback: (pipeline: PipelineEntity) => void) {
|
||||||
|
|
Loading…
Reference in New Issue