mirror of
https://github.com/certd/certd.git
synced 2026-05-16 13:17:29 +08:00
perf: 所有授权增加测试按钮
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { AccessInput, BaseAccess, IsAccess } from "@certd/pipeline";
|
||||
import { AccessInput, BaseAccess, IsAccess, Pager, PageRes, PageSearch } from "@certd/pipeline";
|
||||
import { DomainRecord } from "@certd/plugin-lib";
|
||||
import { AliyunAccess } from "./aliyun-access.js";
|
||||
|
||||
@IsAccess({
|
||||
name: "aliesa",
|
||||
@@ -40,6 +42,68 @@ export class AliesaAccess extends BaseAccess {
|
||||
required: true,
|
||||
})
|
||||
region = "";
|
||||
|
||||
|
||||
@AccessInput({
|
||||
title: "测试",
|
||||
component: {
|
||||
name: "api-test",
|
||||
action: "TestRequest"
|
||||
},
|
||||
helper: "点击测试接口是否正常"
|
||||
})
|
||||
testRequest = true;
|
||||
|
||||
async onTestRequest() {
|
||||
await this.getDomainListPage({
|
||||
pageNo: 1,
|
||||
pageSize: 1,
|
||||
});
|
||||
return "ok"
|
||||
}
|
||||
|
||||
|
||||
async getEsaClient(){
|
||||
const access: AliesaAccess = this
|
||||
const aliAccess = await this.ctx.accessService.getById(access.accessId) as AliyunAccess
|
||||
const endpoint = `esa.${access.region}.aliyuncs.com`
|
||||
return aliAccess.getClient(endpoint)
|
||||
}
|
||||
|
||||
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||
const pager = new Pager(req)
|
||||
const client = await this.getEsaClient()
|
||||
const ret = await client.doRequest({
|
||||
// 接口名称
|
||||
action: "ListSites",
|
||||
// 接口版本
|
||||
version: "2024-09-10",
|
||||
// 接口协议
|
||||
protocol: "HTTPS",
|
||||
// 接口 HTTP 方法
|
||||
method: "GET",
|
||||
authType: "AK",
|
||||
style: "RPC",
|
||||
data: {
|
||||
query: {
|
||||
SiteName: req.searchKey,
|
||||
// ["SiteSearchType"] = "exact";
|
||||
SiteSearchType: "fuzzy",
|
||||
AccessType: "NS",
|
||||
PageSize: pager.pageSize,
|
||||
PageNumber: pager.pageNo,
|
||||
}
|
||||
}
|
||||
})
|
||||
const list = ret.Sites?.map(item => ({
|
||||
domain: item.SiteName,
|
||||
id: item.SiteId,
|
||||
}))
|
||||
return {
|
||||
list: list || [],
|
||||
total: ret.TotalCount,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new AliesaAccess();
|
||||
|
||||
Reference in New Issue
Block a user