chore: 流水线模版初步

This commit is contained in:
xiaojunnuo
2025-06-19 18:17:35 +08:00
parent e11b3becfd
commit 26b395110c
13 changed files with 552 additions and 0 deletions
@@ -0,0 +1,77 @@
import {ALL, Body, Controller, Inject, Post, Provide, Query} from '@midwayjs/core';
import {Constants, CrudController} from '@certd/lib-server';
import { TemplateService } from '../../../modules/pipeline/service/template-service.js';
/**
* 流水线模版
*/
@Provide()
@Controller('/api/pi/template')
export class TemplateController extends CrudController<TemplateService> {
@Inject()
service: TemplateService;
getService() {
return this.service;
}
@Post('/page', { summary: Constants.per.authOnly })
async page(@Body(ALL) body) {
body.query = body.query ?? {};
delete body.query.userId;
const buildQuery = qb => {
qb.andWhere('user_id = :userId', { userId: this.getUserId() });
};
const res = await this.service.page({
query: body.query,
page: body.page,
sort: body.sort,
buildQuery,
});
return this.ok(res);
}
@Post('/list', { summary: Constants.per.authOnly })
async list(@Body(ALL) body) {
body.query = body.query ?? {};
body.query.userId = this.getUserId();
return super.list(body);
}
@Post('/add', { summary: Constants.per.authOnly })
async add(@Body(ALL) bean) {
bean.userId = this.getUserId();
return super.add(bean);
}
@Post('/update', { summary: Constants.per.authOnly })
async update(@Body(ALL) bean) {
await this.service.checkUserId(bean.id, this.getUserId());
delete bean.userId;
return super.update(bean);
}
@Post('/info', { summary: Constants.per.authOnly })
async info(@Query('id') id: number) {
await this.service.checkUserId(id, this.getUserId());
return super.info(id);
}
@Post('/delete', { summary: Constants.per.authOnly })
async delete(@Query('id') id: number) {
await this.service.checkUserId(id, this.getUserId());
return super.delete(id);
}
@Post('/batchDelete', { summary: Constants.per.authOnly })
async batchDelete(@Body('ids') ids: number[]) {
await this.service.batchDelete(ids, this.getUserId());
return this.ok({});
}
@Post('/detail', { summary: Constants.per.authOnly })
async detail(@Query('id') id: number) {
const detail = await this.service.detail(id, this.getUserId());
return this.ok(detail);
}
}
@@ -0,0 +1,52 @@
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
export type PipelineTemplateType = {
input: {
[key: string]: {
value: string;
};
}
}
@Entity('pi_template')
export class TemplateEntity {
@PrimaryGeneratedColumn()
id: number;
@Column({ name: 'user_id', comment: '用户id' })
userId: number;
@Column({ name: 'pipeline_id', comment: '流水线id' })
pipelineId: number;
@Column({ name: 'title', comment: '标题' })
title: string;
@Column({ comment: '配置', length: 40960 })
content: string;
@Column({ comment: '启用/禁用', nullable: true, default: false })
disabled: boolean;
@Column({
name: 'order',
comment: '排序',
nullable: true,
})
order: number;
@Column({
name: 'create_time',
comment: '创建时间',
default: () => 'CURRENT_TIMESTAMP',
})
createTime: Date;
@Column({
name: 'update_time',
comment: '修改时间',
default: () => 'CURRENT_TIMESTAMP',
})
updateTime: Date;
}
@@ -0,0 +1,41 @@
import {Inject, Provide, Scope, ScopeEnum} from '@midwayjs/core';
import {BaseService, SysSettingsService} from '@certd/lib-server';
import {InjectEntityModel} from '@midwayjs/typeorm';
import {Repository} from 'typeorm';
import { TemplateEntity } from '../entity/template.js';
import { PipelineService } from './pipeline-service.js';
@Provide()
@Scope(ScopeEnum.Request, { allowDowngrade: true })
export class TemplateService extends BaseService<TemplateEntity> {
@InjectEntityModel(TemplateEntity)
repository: Repository<TemplateEntity>;
@Inject()
pipelineService: PipelineService;
@Inject()
sysSettingsService: SysSettingsService;
//@ts-ignore
getRepository() {
return this.repository;
}
async detail(id: number, userId: number) {
const info = await this.info(id)
if (!info) {
throw new Error('模板不存在');
}
if (info.userId !== userId) {
throw new Error('无权限');
}
const pipeline = await this.pipelineService.info(info.pipelineId);
return {
template:info,
pipeline: JSON.parse(pipeline.content),
}
}
}
@@ -38,6 +38,7 @@ export class DeployCertToAliyunCDN extends AbstractTaskPlugin {
name: 'output-selector',
from: [...CertApplyPluginNames, 'uploadCertToAliyun'],
},
template:false,
required: true,
})
cert!: string;