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

191 lines
6.1 KiB
TypeScript
Raw Normal View History

2025-07-10 16:32:12 +08:00
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { Constants, CrudController } from '@certd/lib-server';
2026-01-25 00:50:36 +08:00
import { DomainService } from "../../../modules/cert/service/domain-service.js";
import { checkPlus } from '@certd/plus-core';
2026-03-15 14:01:34 +08:00
import { ApiTags } from '@midwayjs/swagger';
2025-07-10 16:32:12 +08:00
/**
* 授权
*/
@Provide()
@Controller('/api/cert/domain')
2026-03-15 14:01:34 +08:00
@ApiTags(['cert'])
2025-07-10 16:32:12 +08:00
export class DomainController extends CrudController<DomainService> {
@Inject()
service: DomainService;
getService(): DomainService {
return this.service;
}
2026-03-15 18:26:49 +08:00
@Post('/page', { description: Constants.per.authOnly, summary: "查询域名分页列表" })
2025-07-10 16:32:12 +08:00
async page(@Body(ALL) body: any) {
2026-04-05 23:49:25 +08:00
const { projectId, userId } = await this.getProjectUserIdRead();
2025-07-10 16:32:12 +08:00
body.query = body.query ?? {};
2026-02-13 21:28:17 +08:00
body.query.projectId = projectId;
body.query.userId = userId;
2025-07-10 16:32:12 +08:00
const domain = body.query.domain;
delete body.query.domain;
const bq = qb => {
if (domain) {
qb.andWhere('domain like :domain', { domain: `%${domain}%` });
}
};
const pageRet = await this.getService().page({
query: body.query,
page: body.page,
sort: body.sort,
buildQuery: bq,
});
return this.ok(pageRet);
}
2026-03-15 18:26:49 +08:00
@Post('/list', { description: Constants.per.authOnly, summary: "查询域名列表" })
2025-07-10 16:32:12 +08:00
async list(@Body(ALL) body: any) {
2026-04-05 23:49:25 +08:00
const { projectId, userId } = await this.getProjectUserIdRead();
2025-07-10 16:32:12 +08:00
body.query = body.query ?? {};
2026-02-13 21:28:17 +08:00
body.query.projectId = projectId;
body.query.userId = userId;
2025-07-10 16:32:12 +08:00
const list = await this.getService().list(body);
return this.ok(list);
}
2026-03-15 18:26:49 +08:00
@Post('/add', { description: Constants.per.authOnly, summary: "添加域名" })
2025-07-10 16:32:12 +08:00
async add(@Body(ALL) bean: any) {
2026-04-05 23:49:25 +08:00
const { projectId, userId } = await this.getProjectUserIdRead();
2026-02-13 21:28:17 +08:00
bean.projectId = projectId;
bean.userId = userId;
2025-07-10 16:32:12 +08:00
return super.add(bean);
}
2026-03-15 18:26:49 +08:00
@Post('/update', { description: Constants.per.authOnly, summary: "更新域名" })
2025-07-10 16:32:12 +08:00
async update(@Body(ALL) bean: any) {
2026-02-13 21:28:17 +08:00
await this.checkOwner(this.getService(), bean.id, "write");
2025-07-10 16:32:12 +08:00
delete bean.userId;
2026-02-13 21:28:17 +08:00
delete bean.projectId;
2025-07-10 16:32:12 +08:00
return super.update(bean);
}
2026-03-15 18:26:49 +08:00
@Post('/info', { description: Constants.per.authOnly, summary: "查询域名详情" })
2025-07-10 16:32:12 +08:00
async info(@Query('id') id: number) {
2026-02-13 21:28:17 +08:00
await this.checkOwner(this.getService(), id, "read");
2025-07-10 16:32:12 +08:00
return super.info(id);
}
2026-03-15 18:26:49 +08:00
@Post('/delete', { description: Constants.per.authOnly, summary: "删除域名" })
2025-07-10 16:32:12 +08:00
async delete(@Query('id') id: number) {
2026-02-13 21:28:17 +08:00
await this.checkOwner(this.getService(), id, "write");
2025-07-10 16:32:12 +08:00
return super.delete(id);
}
2026-03-15 18:26:49 +08:00
@Post('/deleteByIds', { description: Constants.per.authOnly, summary: "批量删除域名" })
2025-07-10 16:32:12 +08:00
async deleteByIds(@Body(ALL) body: any) {
2026-04-05 23:49:25 +08:00
const { projectId, userId } = await this.getProjectUserIdRead();
2025-07-10 16:32:12 +08:00
await this.service.delete(body.ids, {
2026-02-13 21:28:17 +08:00
userId: userId,
projectId: projectId,
2025-07-10 16:32:12 +08:00
});
return this.ok();
}
2026-01-16 18:18:39 +08:00
2026-03-15 18:26:49 +08:00
@Post('/import/start', { description: Constants.per.authOnly, summary: "开始域名导入任务" })
2026-01-25 00:50:36 +08:00
async importStart(@Body(ALL) body: any) {
2026-01-25 23:08:42 +08:00
checkPlus();
2026-04-05 23:49:25 +08:00
const { projectId, userId } = await this.getProjectUserIdRead();
2026-01-25 00:50:36 +08:00
const { key } = body;
2026-01-16 18:18:39 +08:00
const req = {
2026-04-05 23:49:25 +08:00
key,
2026-02-13 21:28:17 +08:00
userId: userId,
projectId: projectId,
2026-01-16 18:18:39 +08:00
}
2026-01-25 00:50:36 +08:00
await this.service.startDomainImportTask(req);
2026-01-22 00:59:28 +08:00
return this.ok();
}
2026-03-15 18:26:49 +08:00
@Post('/import/status', { description: Constants.per.authOnly, summary: "查询域名导入任务状态" })
2026-01-25 00:50:36 +08:00
async importStatus() {
2026-04-05 23:49:25 +08:00
const { projectId, userId } = await this.getProjectUserIdRead();
2026-01-25 00:50:36 +08:00
const req = {
2026-02-13 21:28:17 +08:00
userId: userId,
projectId: projectId,
2026-01-25 00:50:36 +08:00
}
const task = await this.service.getDomainImportTaskStatus(req);
return this.ok(task);
}
2026-03-15 18:26:49 +08:00
@Post('/import/delete', { description: Constants.per.authOnly, summary: "删除域名导入任务" })
2026-01-25 00:50:36 +08:00
async importDelete(@Body(ALL) body: any) {
2026-04-05 23:49:25 +08:00
const { projectId, userId } = await this.getProjectUserIdRead();
2026-01-25 00:50:36 +08:00
const { key } = body;
const req = {
2026-02-13 21:28:17 +08:00
userId: userId,
projectId: projectId,
2026-01-25 00:50:36 +08:00
key,
}
await this.service.deleteDomainImportTask(req);
return this.ok();
}
2026-03-15 18:26:49 +08:00
@Post('/import/save', { description: Constants.per.authOnly, summary: "保存域名导入任务" })
2026-01-25 13:01:12 +08:00
async importSave(@Body(ALL) body: any) {
2026-01-25 23:08:42 +08:00
checkPlus();
2026-04-05 23:49:25 +08:00
const { projectId, userId } = await this.getProjectUserIdRead();
2026-01-25 13:01:12 +08:00
const { dnsProviderType, dnsProviderAccessId, key } = body;
const req = {
2026-02-13 21:28:17 +08:00
userId: userId,
projectId: projectId,
2026-04-05 23:49:25 +08:00
dnsProviderType, dnsProviderAccessId, key
2026-01-25 13:01:12 +08:00
}
const item = await this.service.saveDomainImportTask(req);
return this.ok(item);
}
2026-01-25 00:50:36 +08:00
2026-03-15 18:26:49 +08:00
@Post('/sync/expiration/start', { description: Constants.per.authOnly, summary: "开始同步域名过期时间任务" })
2026-01-25 00:50:36 +08:00
async syncExpirationStart(@Body(ALL) body: any) {
2026-04-05 23:49:25 +08:00
const { projectId, userId } = await this.getProjectUserIdRead();
2026-01-25 00:50:36 +08:00
await this.service.startSyncExpirationTask({
2026-02-13 21:28:17 +08:00
userId: userId,
projectId: projectId,
2026-01-22 00:59:28 +08:00
})
2026-01-16 18:18:39 +08:00
return this.ok();
}
2026-03-15 18:26:49 +08:00
@Post('/sync/expiration/status', { description: Constants.per.authOnly, summary: "查询同步域名过期时间任务状态" })
2026-01-25 00:50:36 +08:00
async syncExpirationStatus(@Body(ALL) body: any) {
2026-04-05 23:49:25 +08:00
const { projectId, userId } = await this.getProjectUserIdRead();
2026-01-25 00:50:36 +08:00
const status = await this.service.getSyncExpirationTaskStatus({
2026-02-13 21:28:17 +08:00
userId: userId,
projectId: projectId,
2026-01-25 00:50:36 +08:00
})
return this.ok(status);
}
2026-01-16 18:18:39 +08:00
2026-04-05 23:49:25 +08:00
@Post('/setting/save', { description: Constants.per.authOnly, summary: "保存域名监控设置" })
async settingSave(@Body(ALL) body: any) {
const { projectId, userId } = await this.getProjectUserIdWrite();
await this.service.monitorSettingSave({
userId: userId,
projectId: projectId,
setting: {...body},
})
return this.ok();
}
@Post('/setting/get', { description: Constants.per.authOnly, summary: "查询域名监控设置" })
async settingGet() {
const { projectId, userId } = await this.getProjectUserIdRead();
const setting = await this.service.monitorSettingGet({
userId: userId,
projectId: projectId,
})
return this.ok(setting);
}
2025-07-10 16:32:12 +08:00
}