perf: 证书仓库

This commit is contained in:
xiaojunnuo
2025-01-15 01:05:34 +08:00
parent 52a4fd3318
commit 91e7f45a1c
48 changed files with 615 additions and 130 deletions
@@ -0,0 +1,28 @@
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
import { BaseController, Constants } from '@certd/lib-server';
import { CnameRecordService } from '../../../modules/cname/service/cname-record-service.js';
import { CnameProviderService } from '../../../modules/cname/service/cname-provider-service.js';
/**
* 授权
*/
@Provide()
@Controller('/api/cname/provider')
export class CnameProviderController extends BaseController {
@Inject()
service: CnameRecordService;
@Inject()
providerService: CnameProviderService;
getService(): CnameRecordService {
return this.service;
}
@Post('/list', { summary: Constants.per.authOnly })
async list(@Body(ALL) body: any) {
body.query = body.query ?? {};
body.query.userId = this.getUserId();
const res = await this.providerService.list({});
return this.ok(res);
}
}
@@ -0,0 +1,94 @@
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { Constants, CrudController } from '@certd/lib-server';
import { CnameRecordService } from '../../../modules/cname/service/cname-record-service.js';
/**
* 授权
*/
@Provide()
@Controller('/api/cname/record')
export class CnameRecordController extends CrudController<CnameRecordService> {
@Inject()
service: CnameRecordService;
getService(): CnameRecordService {
return this.service;
}
@Post('/page', { summary: Constants.per.authOnly })
async page(@Body(ALL) body: any) {
body.query = body.query ?? {};
body.query.userId = this.getUserId();
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);
}
@Post('/list', { summary: Constants.per.authOnly })
async list(@Body(ALL) body: any) {
body.query = body.query ?? {};
body.query.userId = this.getUserId();
const list = await this.getService().list(body);
return this.ok(list);
}
@Post('/add', { summary: Constants.per.authOnly })
async add(@Body(ALL) bean: any) {
bean.userId = this.getUserId();
return super.add(bean);
}
@Post('/update', { summary: Constants.per.authOnly })
async update(@Body(ALL) bean: any) {
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('/deleteByIds', { summary: Constants.per.authOnly })
async deleteByIds(@Body(ALL) body: any) {
await this.service.delete(body.ids, {
userId: this.getUserId(),
});
return this.ok();
}
@Post('/getByDomain', { summary: Constants.per.authOnly })
async getByDomain(@Body(ALL) body: { domain: string; createOnNotFound: boolean }) {
const userId = this.getUserId();
const res = await this.service.getByDomain(body.domain, userId, body.createOnNotFound);
return this.ok(res);
}
@Post('/verify', { summary: Constants.per.authOnly })
async verify(@Body(ALL) body: { id: string }) {
const userId = this.getUserId();
await this.service.checkUserId(body.id, userId);
const res = await this.service.verify(body.id);
return this.ok(res);
}
}