Files
certd/packages/ui/certd-server/src/controller/user/pipeline/sub-domain-controller.ts
T

97 lines
3.4 KiB
TypeScript
Raw Normal View History

import { Constants, CrudController } from '@certd/lib-server';
import { DomainParser } from '@certd/plugin-cert';
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { SubDomainService } from "../../../modules/pipeline/service/sub-domain-service.js";
import { TaskServiceBuilder } from '../../../modules/pipeline/service/getter/task-service-getter.js';
2026-03-15 14:01:34 +08:00
import { ApiTags } from '@midwayjs/swagger';
/**
* 子域名托管
*/
@Provide()
@Controller('/api/pi/subDomain')
2026-03-15 14:01:34 +08:00
@ApiTags(['pipeline-subdomain'])
export class SubDomainController extends CrudController<SubDomainService> {
@Inject()
service: SubDomainService;
@Inject()
taskServiceBuilder: TaskServiceBuilder;
getService() {
return this.service;
}
2026-03-15 18:26:49 +08:00
@Post('/parseDomain', { description: Constants.per.authOnly, summary: "解析域名" })
async parseDomain(@Body("fullDomain") fullDomain:string) {
2026-02-13 21:28:17 +08:00
const {projectId,userId} = await this.getProjectUserIdRead();
const taskService = this.taskServiceBuilder.create({ userId: userId, projectId: projectId });
const subDomainGetter = await taskService.getSubDomainsGetter();
const domainParser = new DomainParser(subDomainGetter)
const domain = await domainParser.parse(fullDomain)
return this.ok(domain);
}
2026-03-15 18:26:49 +08:00
@Post('/page', { description: Constants.per.authOnly, summary: "查询子域名分页列表" })
async page(@Body(ALL) body) {
2026-02-13 21:28:17 +08:00
const {userId,projectId} = await this.getProjectUserIdRead();
body.query = body.query ?? {};
delete body.query.userId;
2026-02-13 21:28:17 +08:00
body.query.projectId = projectId;
const buildQuery = qb => {
2026-02-13 21:28:17 +08:00
qb.andWhere('user_id = :userId', { userId: userId });
};
const res = await this.service.page({
query: body.query,
page: body.page,
sort: body.sort,
buildQuery,
});
return this.ok(res);
}
2026-03-15 18:26:49 +08:00
@Post('/list', { description: Constants.per.authOnly, summary: "查询子域名列表" })
async list(@Body(ALL) body) {
2026-02-13 21:28:17 +08:00
const {userId,projectId} = await this.getProjectUserIdRead();
body.query = body.query ?? {};
2026-02-13 21:28:17 +08:00
body.query.userId = userId;
body.query.projectId = projectId;
return super.list(body);
}
2026-03-15 18:26:49 +08:00
@Post('/add', { description: Constants.per.authOnly, summary: "添加子域名" })
async add(@Body(ALL) bean) {
2026-02-13 21:28:17 +08:00
const {userId,projectId} = await this.getProjectUserIdRead();
bean.userId = userId;
bean.projectId = projectId;
return super.add(bean);
}
2026-03-15 18:26:49 +08:00
@Post('/update', { description: Constants.per.authOnly, summary: "更新子域名" })
async update(@Body(ALL) bean) {
2026-02-13 21:28:17 +08:00
await this.checkOwner(this.getService(), bean.id, "write");
delete bean.userId;
2026-02-13 21:28:17 +08:00
delete bean.projectId;
return super.update(bean);
}
2026-03-15 18:26:49 +08:00
@Post('/info', { description: Constants.per.authOnly, summary: "查询子域名详情" })
async info(@Query('id') id: number) {
2026-02-13 21:28:17 +08:00
await this.checkOwner(this.getService(), id, "read");
return super.info(id);
}
2026-03-15 18:26:49 +08:00
@Post('/delete', { description: Constants.per.authOnly, summary: "删除子域名" })
async delete(@Query('id') id: number) {
2026-02-13 21:28:17 +08:00
await this.checkOwner(this.getService(), id, "write");
return super.delete(id);
}
2026-03-15 18:26:49 +08:00
@Post('/batchDelete', { description: Constants.per.authOnly, summary: "批量删除子域名" })
async batchDelete(@Body('ids') ids: number[]) {
2026-02-13 21:28:17 +08:00
const {userId,projectId} = await this.getProjectUserIdWrite();
await this.service.batchDelete(ids, userId, projectId);
return this.ok({});
}
}