chore: format

This commit is contained in:
xiaojunnuo
2026-05-31 01:41:33 +08:00
parent acd440106b
commit 4b57a0d729
557 changed files with 12530 additions and 14039 deletions
@@ -13,8 +13,8 @@ import { CertReader } from "@certd/plugin-lib";
/**
*/
@Provide()
@Controller('/api/monitor/cert')
@ApiTags(['cert'])
@Controller("/api/monitor/cert")
@ApiTags(["cert"])
export class CertInfoController extends CrudController<CertInfoService> {
@Inject()
service: CertInfoService;
@@ -30,12 +30,12 @@ export class CertInfoController extends CrudController<CertInfoService> {
return this.service;
}
@Post('/page', { description: Constants.per.authOnly, summary: "查询证书分页列表" })
@Post("/page", { description: Constants.per.authOnly, summary: "查询证书分页列表" })
async page(@Body(ALL) body: any) {
body.query = body.query ?? {};
const { projectId, userId } = await this.getProjectUserIdRead()
body.query.projectId = projectId
const { projectId, userId } = await this.getProjectUserIdRead();
body.query.projectId = projectId;
body.query.userId = userId;
const domains = body.query?.domains;
delete body.query.domains;
@@ -49,21 +49,21 @@ export class CertInfoController extends CrudController<CertInfoService> {
query: body.query,
page: body.page,
sort: body.sort,
buildQuery: (bq) => {
buildQuery: bq => {
if (domains) {
bq.andWhere('domains like :domains', { domains: `%${domains}%` });
bq.andWhere("domains like :domains", { domains: `%${domains}%` });
}
if (expiresLeft) {
const willExpire = dayjs().add(DEFAULT_WILL_EXPIRE_DAYS, 'day').valueOf();
const willExpire = dayjs().add(DEFAULT_WILL_EXPIRE_DAYS, "day").valueOf();
if (expiresLeft === "expired") {
bq.andWhere('expires_time < :now', { now: Date.now() });
bq.andWhere("expires_time < :now", { now: Date.now() });
} else if (expiresLeft === "expiring") {
bq.andWhere('expires_time <= :willExpire and expires_time > :now', { willExpire, now: Date.now() });
bq.andWhere("expires_time <= :willExpire and expires_time > :now", { willExpire, now: Date.now() });
} else if (expiresLeft === "noExpired") {
bq.andWhere('expires_time > :willExpire', { willExpire });
bq.andWhere("expires_time > :willExpire", { willExpire });
}
}
}
},
});
const records = res.records;
@@ -79,71 +79,70 @@ export class CertInfoController extends CrudController<CertInfoService> {
return this.ok(res);
}
@Post('/list', { description: Constants.per.authOnly, summary: "查询证书列表" })
@Post("/list", { description: Constants.per.authOnly, summary: "查询证书列表" })
async list(@Body(ALL) body: any) {
body.query = body.query ?? {};
const { projectId, userId } = await this.getProjectUserIdRead()
body.query.projectId = projectId
const { projectId, userId } = await this.getProjectUserIdRead();
body.query.projectId = projectId;
body.query.userId = userId;
return await super.list(body);
}
@Post('/getOptionsByIds', { description: Constants.per.authOnly, summary: "根据ID列表获取证书选项" })
async getOptionsByIds(@Body(ALL) body: {ids:any[]}) {
const { projectId, userId } = await this.getProjectUserIdRead()
@Post("/getOptionsByIds", { description: Constants.per.authOnly, summary: "根据ID列表获取证书选项" })
async getOptionsByIds(@Body(ALL) body: { ids: any[] }) {
const { projectId, userId } = await this.getProjectUserIdRead();
const list = await this.service.list({
query:{
query: {
projectId,
userId,
},
buildQuery: (bq: SelectQueryBuilder<any>) => {
bq.andWhere('id in (:...ids)', { ids: body.ids });
}
})
bq.andWhere("id in (:...ids)", { ids: body.ids });
},
});
const safeList =list.map((item:any) => {
const domainsArr = item.domains? item.domains.split(',') : [];
const safeList = list.map((item: any) => {
const domainsArr = item.domains ? item.domains.split(",") : [];
return {
id: item.id,
domain: item.domain,
domains:domainsArr,
domains: domainsArr,
userId: item.userId,
}
})
};
});
return this.ok(safeList);
}
@Post('/add', { description: Constants.per.authOnly, summary: "添加证书" })
@Post("/add", { description: Constants.per.authOnly, summary: "添加证书" })
async add(@Body(ALL) bean: any) {
const { projectId, userId } = await this.getProjectUserIdWrite()
bean.projectId = projectId
const { projectId, userId } = await this.getProjectUserIdWrite();
bean.projectId = projectId;
bean.userId = userId;
return await super.add(bean);
}
@Post('/update', { description: Constants.per.authOnly, summary: "更新证书" })
@Post("/update", { description: Constants.per.authOnly, summary: "更新证书" })
async update(@Body(ALL) bean) {
await this.checkOwner(this.service,bean.id,"write");
await this.checkOwner(this.service, bean.id, "write");
delete bean.userId;
delete bean.projectId;
return await super.update(bean);
}
@Post('/info', { description: Constants.per.authOnly, summary: "查询证书详情" })
async info(@Query('id') id: number) {
await this.checkOwner(this.service,id,"read");
@Post("/info", { description: Constants.per.authOnly, summary: "查询证书详情" })
async info(@Query("id") id: number) {
await this.checkOwner(this.service, id, "read");
return await super.info(id);
}
@Post('/delete', { description: Constants.per.authOnly, summary: "删除证书" })
async delete(@Query('id') id: number) {
await this.checkOwner(this.service,id,"write");
@Post("/delete", { description: Constants.per.authOnly, summary: "删除证书" })
async delete(@Query("id") id: number) {
await this.checkOwner(this.service, id, "write");
return await super.delete(id);
}
@Post('/all', { description: Constants.per.authOnly, summary: "查询所有证书" })
@Post("/all", { description: Constants.per.authOnly, summary: "查询所有证书" })
async all() {
const { projectId, userId } = await this.getProjectUserIdRead()
const { projectId, userId } = await this.getProjectUserIdRead();
const list: any = await this.service.find({
where: {
projectId,
@@ -153,32 +152,30 @@ export class CertInfoController extends CrudController<CertInfoService> {
return this.ok(list);
}
@Post('/getCert', { description: Constants.per.authOnly, summary: "获取证书信息" })
async getCert(@Query('id') id: number) {
await this.checkOwner(this.getService(),id,"read");
@Post("/getCert", { description: Constants.per.authOnly, summary: "获取证书信息" })
async getCert(@Query("id") id: number) {
await this.checkOwner(this.getService(), id, "read");
const certInfoEntity = await this.service.info(id);
const certInfo = JSON.parse(certInfoEntity.certInfo);
if (certInfo?.crt) {
const certReader = new CertReader(certInfo);
certInfo.detail = certReader.detail
certInfo.detail = certReader.detail;
}
return this.ok(certInfo);
}
@Get('/download', { description: Constants.per.authOnly, summary: "下载证书文件" })
async download(@Query('id') id: number) {
const {userId,projectId} =await this.checkOwner(this.getService(),id,"read");
const certInfo = await this.getService().info(id)
@Get("/download", { description: Constants.per.authOnly, summary: "下载证书文件" })
async download(@Query("id") id: number) {
const { userId, projectId } = await this.checkOwner(this.getService(), id, "read");
const certInfo = await this.getService().info(id);
if (certInfo == null) {
throw new CommonException('file not found');
throw new CommonException("file not found");
}
if (certInfo.userId !== userId) {
throw new CommonException('file not found');
throw new CommonException("file not found");
}
if (projectId && certInfo.projectId !== projectId) {
throw new CommonException('file not found');
throw new CommonException("file not found");
}
// koa send file
// 下载文件的名称
@@ -186,12 +183,12 @@ export class CertInfoController extends CrudController<CertInfoService> {
// 要下载的文件的完整路径
const path = certInfo.certFile;
if (!path) {
throw new CommonException('file not found');
throw new CommonException("file not found");
}
logger.info(`download:${path}`);
// 以流的形式下载文件
this.ctx.attachment(path);
this.ctx.set('Content-Type', 'application/octet-stream');
this.ctx.set("Content-Type", "application/octet-stream");
return fs.createReadStream(path);
}