fix: 修复京东云报错不准确的bug

This commit is contained in:
xiaojunnuo
2026-03-17 00:05:53 +08:00
parent d01bfbec96
commit 10dd89ae62
7 changed files with 64 additions and 64 deletions

View File

@@ -174,7 +174,7 @@ export default async (client, userOpts) => {
} catch (e) {
log(`[auto] [${d}] challengeCreateFn threw error: ${e.message}`);
log(`[auto] [${d}] challengeCreateFn threw error: ${e.message || e}`);
await deactivateAuth(e);
throw e;
}

View File

@@ -244,10 +244,11 @@ export class AccessService extends BaseService<AccessEntity> {
}
const newAccess = {
...access,
userId:-1,
id: undefined,
projectId,
}
await this.add(newAccess);
await this.repository.save(newAccess);
return newAccess.id;
}
}

View File

@@ -1,4 +1,4 @@
import {AccessInput, BaseAccess, IsAccess, Pager, PageRes, PageSearch} from '@certd/pipeline';
import { AccessInput, BaseAccess, IsAccess, Pager, PageRes, PageSearch } from '@certd/pipeline';
import { DomainRecord } from '@certd/plugin-lib';
/**
@@ -19,7 +19,7 @@ export class JDCloudAccess extends BaseAccess {
component: {
placeholder: 'AccessKeyID',
},
helper:"[获取密钥](https://uc.jdcloud.com/account/accesskey)",
helper: "[获取密钥](https://uc.jdcloud.com/account/accesskey)",
required: true,
})
accessKeyId = '';
@@ -34,7 +34,7 @@ export class JDCloudAccess extends BaseAccess {
secretAccessKey = '';
@AccessInput({
@AccessInput({
title: "测试",
component: {
name: "api-test",
@@ -55,8 +55,8 @@ export class JDCloudAccess extends BaseAccess {
}
async getJDDomainService() {
const {JDDomainService} = await import("@certd/jdcloud")
async getJDDomainService() {
const { JDDomainService } = await import("@certd/jdcloud")
const service = new JDDomainService({
credentials: {
accessKeyId: this.accessKeyId,
@@ -68,24 +68,34 @@ export class JDCloudAccess extends BaseAccess {
}
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
const pager = new Pager(req);
const service = await this.getJDDomainService();
const domainRes = await service.describeDomains({
domainName: req.searchKey,
pageNumber: pager.pageNo,
pageSize: pager.pageSize,
})
let list = domainRes.result?.dataList || []
list = list.map((item: any) => ({
id: item.domainId,
domain: item.domainName,
}));
return {
total:domainRes.result.totalCount || list.length,
list,
};
const pager = new Pager(req);
const service = await this.getJDDomainService();
const domainRes = await this.catchCall(() => service.describeDomains({
domainName: req.searchKey,
pageNumber: pager.pageNo,
pageSize: pager.pageSize,
}))
let list = domainRes.result?.dataList || []
list = list.map((item: any) => ({
id: item.domainId,
domain: item.domainName,
}));
return {
total: domainRes.result.totalCount || list.length,
list,
};
}
async catchCall<T=any>(fn: () => Promise<T>): Promise<T> {
try {
return await fn();
} catch (e) {
if (e.error) {
this.ctx.logger.error(JSON.stringify(e.error))
throw new Error(JSON.stringify(e.error))
}
throw e
}
}
}
new JDCloudAccess();

View File

@@ -8,7 +8,7 @@ import { JDCloudAccess } from "./access.js";
desc: "京东云DNS解析提供商",
accessType: "jdcloud",
icon: "svg:icon-jdcloud",
order:3,
order: 3,
})
export class JDCloudDnsProvider extends AbstractDnsProvider {
access!: JDCloudAccess;
@@ -36,8 +36,8 @@ export class JDCloudDnsProvider extends AbstractDnsProvider {
}
const list = domainRes.result.dataList
const found = list.find((item) => item.domainName === domain)
if (!found){
const found = list.find((item) => item.domainName === domain)
if (!found) {
throw new Error(`域名${domain}在此京东云账号中不存在`)
}
@@ -54,44 +54,33 @@ export class JDCloudDnsProvider extends AbstractDnsProvider {
* weight Integer False 解析记录的权重目前支持权重的有A/AAAA/CNAME/JNAMEA/AAAA权重范围0-100、CNAME/JNAME权重范围1-100。
* viewValue Integer True 解析线路的ID请调用describeViewTree接口获取基础解
*/
try{
const res = await service.createResourceRecord({
domainId: domainId,
req:{
hostRecord: hostRecord,
hostValue: value,
type: type,
ttl: 200,
viewValue:-1,
}
})
return {
recordId: res.result.dataList.id,
domainId: domainId
};
}catch (e) {
if (e.error){
this.logger.error(JSON.stringify(e.error))
throw new Error(JSON.stringify(e.error))
const res = await this.access.catchCall(() => service.createResourceRecord({
domainId: domainId,
req: {
hostRecord: hostRecord,
hostValue: value,
type: type,
ttl: 200,
viewValue: -1,
}
throw e
}
}))
return {
recordId: res.result.dataList.id,
domainId: domainId
};
}
async removeRecord(options: RemoveRecordOptions<any>): Promise<any> {
const record = options.recordRes;
const service = await this.getJDDomainService();
await service.deleteResourceRecord({
await this.access.catchCall(() => service.deleteResourceRecord({
domainId: record.domainId,
resourceRecordId: record.recordId
})
}))
}
private async getJDDomainService() {
private async getJDDomainService() {
return await this.access.getJDDomainService();
}

View File

@@ -71,7 +71,7 @@ export class JDCloudDeployToCDN extends AbstractTaskPlugin {
this.logger.info(`开始上传证书`);
const sslService = await this.getSslClient(access);
const res = await sslService.uploadCert({
const res = await access.catchCall(() => sslService.uploadCert({
// certName String True 证书名称
// keyFile String True 私钥
// certFile String True 证书
@@ -80,7 +80,7 @@ export class JDCloudDeployToCDN extends AbstractTaskPlugin {
keyFile: certInfo.key,
certFile: certInfo.crt,
aliasName: certName
});
}));
certId = res.result.certId;
}
@@ -152,10 +152,10 @@ export class JDCloudDeployToCDN extends AbstractTaskPlugin {
* pageNumber Integer False 1 pageNumber,默认值1
* pageSize
*/
const res = await service.getDomainList({
const res = await access.catchCall(() => service.getDomainList({
pageNumber: 1,
pageSize: 50
});
}));
// @ts-ignore
const list = res?.result?.domains;
if (!list || list.length === 0) {

View File

@@ -85,7 +85,7 @@ export class JDCloudUpdateCert extends AbstractTaskPlugin {
const certInfo = this.cert as CertInfo
for (const certId of this.certIds) {
this.logger.info(`开始更新证书:${certId}`)
const res = await service.updateCert({
const res = await access.catchCall(() => service.updateCert({
/*
@param {string} opts.certId - 证书Id
@param {string} opts.certId - 证书ID
@@ -96,7 +96,7 @@ export class JDCloudUpdateCert extends AbstractTaskPlugin {
certId,
certFile: certInfo.crt,
keyFile:certInfo.key,
})
}))
this.logger.info(`更新证书${certId}成功:${JSON.stringify(res)}`);
await this.ctx.utils.sleep(2000)
}
@@ -126,10 +126,10 @@ export class JDCloudUpdateCert extends AbstractTaskPlugin {
* pageNumber Integer False 1 pageNumber,默认值1
* pageSize
*/
const res = await service.describeCerts({
const res = await access.catchCall(() => service.describeCerts({
pageNumber: 1,
pageSize: 100,
})
}))
// @ts-ignore
const list = res?.result?.certListDetails
if (!list || list.length === 0) {

View File

@@ -61,7 +61,7 @@ export class JDCloudUploadCert extends AbstractTaskPlugin {
const service = await this.getClient(access);
const certInfo = this.cert as CertInfo;
const res = await service.uploadCert({
const res = await access.catchCall(() => service.uploadCert({
/*
@param {string} opts.certName - 证书名称
@param {string} opts.keyFile - 私钥
@@ -71,7 +71,7 @@ export class JDCloudUploadCert extends AbstractTaskPlugin {
certName: this.appendTimeSuffix(this.certName || "certd"),
certFile: certInfo.crt,
keyFile: certInfo.key
});
}));
this.jdcloudCertId = res.result.certId;
this.logger.info(`上传证书成功:${JSON.stringify(res)}`);
}