mirror of
https://github.com/certd/certd.git
synced 2026-07-15 02:07:38 +08:00
perf: 所有授权增加测试按钮
This commit is contained in:
@@ -49,6 +49,62 @@ export class LuckyAccess extends BaseAccess {
|
||||
encrypt: true,
|
||||
})
|
||||
openToken = "";
|
||||
|
||||
|
||||
@AccessInput({
|
||||
title: "测试",
|
||||
component: {
|
||||
name: "api-test",
|
||||
action: "TestRequest",
|
||||
},
|
||||
helper: "点击测试接口看是否正常",
|
||||
})
|
||||
testRequest = true;
|
||||
|
||||
async onTestRequest() {
|
||||
await this.getCertList();
|
||||
return "ok";
|
||||
}
|
||||
|
||||
|
||||
async doRequest(req: { urlPath: string; data: any; method?: string }) {
|
||||
const { urlPath, data, method } = req;
|
||||
let url = `${this.url}/${this.safePath || ""}${urlPath}?_=${Math.floor(new Date().getTime())}`;
|
||||
// 从第7个字符起,将//替换成/
|
||||
const protocol = url.substring(0, 7);
|
||||
let suffix = url.substring(7);
|
||||
suffix = suffix.replaceAll("//", "/");
|
||||
suffix = suffix.replaceAll("//", "/");
|
||||
url = protocol + suffix;
|
||||
|
||||
const headers: any = {
|
||||
// Origin: access.url,
|
||||
"Content-Type": "application/json",
|
||||
// "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.95 Safari/537.36",
|
||||
};
|
||||
headers["openToken"] = this.openToken;
|
||||
const res = await this.ctx.http.request({
|
||||
method: method || "POST",
|
||||
url,
|
||||
data,
|
||||
headers,
|
||||
skipSslVerify: true,
|
||||
});
|
||||
if (res.ret !== 0) {
|
||||
throw new Error(`请求失败:${res.msg}`);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
async getCertList() {
|
||||
const res = await this.doRequest({
|
||||
urlPath: "/api/ssl",
|
||||
data: {},
|
||||
method: "GET",
|
||||
});
|
||||
const list = res.list || [];
|
||||
return list
|
||||
}
|
||||
}
|
||||
|
||||
new LuckyAccess();
|
||||
|
||||
@@ -82,8 +82,7 @@ export class LuckyUpdateCert extends AbstractPlusTaskPlugin {
|
||||
throw new Error(`没有找到证书:Key=${item},请确认该证书是否存在`);
|
||||
}
|
||||
const remark = old.Remark;
|
||||
const res = await this.doRequest({
|
||||
access,
|
||||
const res = await access.doRequest({
|
||||
urlPath: "/api/ssl",
|
||||
method: "PUT",
|
||||
data: {
|
||||
@@ -107,44 +106,9 @@ export class LuckyUpdateCert extends AbstractPlusTaskPlugin {
|
||||
this.logger.info("部署成功");
|
||||
}
|
||||
|
||||
async doRequest(req: { access: LuckyAccess; urlPath: string; data: any; method?: string }) {
|
||||
const { access, urlPath, data, method } = req;
|
||||
let url = `${access.url}/${access.safePath || ""}${urlPath}?_=${Math.floor(new Date().getTime())}`;
|
||||
// 从第7个字符起,将//替换成/
|
||||
const protocol = url.substring(0, 7);
|
||||
let suffix = url.substring(7);
|
||||
suffix = suffix.replaceAll("//", "/");
|
||||
suffix = suffix.replaceAll("//", "/");
|
||||
url = protocol + suffix;
|
||||
|
||||
const headers: any = {
|
||||
// Origin: access.url,
|
||||
"Content-Type": "application/json",
|
||||
// "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.95 Safari/537.36",
|
||||
};
|
||||
headers["openToken"] = access.openToken;
|
||||
const res = await this.http.request({
|
||||
method: method || "POST",
|
||||
url,
|
||||
data,
|
||||
headers,
|
||||
skipSslVerify: true,
|
||||
});
|
||||
if (res.ret !== 0) {
|
||||
throw new Error(`请求失败:${res.msg}`);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
async onGetCertList() {
|
||||
const access: LuckyAccess = await this.getAccess<LuckyAccess>(this.accessId);
|
||||
const res = await this.doRequest({
|
||||
access,
|
||||
urlPath: "/api/ssl",
|
||||
data: {},
|
||||
method: "GET",
|
||||
});
|
||||
const list = res.list;
|
||||
const list = await access.getCertList();
|
||||
if (!list || list.length === 0) {
|
||||
throw new Error("没有找到证书,请先在SSL/TLS证书页面中手动上传一次证书");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user