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
+1 -1
View File
@@ -174,7 +174,7 @@ export default async (client, userOpts) => {
} catch (e) { } catch (e) {
log(`[auto] [${d}] challengeCreateFn threw error: ${e.message}`); log(`[auto] [${d}] challengeCreateFn threw error: ${e.message || e}`);
await deactivateAuth(e); await deactivateAuth(e);
throw e; throw e;
} }
@@ -244,10 +244,11 @@ export class AccessService extends BaseService<AccessEntity> {
} }
const newAccess = { const newAccess = {
...access, ...access,
userId:-1,
id: undefined, id: undefined,
projectId, projectId,
} }
await this.add(newAccess); await this.repository.save(newAccess);
return newAccess.id; return newAccess.id;
} }
} }
@@ -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'; import { DomainRecord } from '@certd/plugin-lib';
/** /**
@@ -19,7 +19,7 @@ export class JDCloudAccess extends BaseAccess {
component: { component: {
placeholder: 'AccessKeyID', placeholder: 'AccessKeyID',
}, },
helper:"[获取密钥](https://uc.jdcloud.com/account/accesskey)", helper: "[获取密钥](https://uc.jdcloud.com/account/accesskey)",
required: true, required: true,
}) })
accessKeyId = ''; accessKeyId = '';
@@ -34,7 +34,7 @@ export class JDCloudAccess extends BaseAccess {
secretAccessKey = ''; secretAccessKey = '';
@AccessInput({ @AccessInput({
title: "测试", title: "测试",
component: { component: {
name: "api-test", name: "api-test",
@@ -55,8 +55,8 @@ export class JDCloudAccess extends BaseAccess {
} }
async getJDDomainService() { async getJDDomainService() {
const {JDDomainService} = await import("@certd/jdcloud") const { JDDomainService } = await import("@certd/jdcloud")
const service = new JDDomainService({ const service = new JDDomainService({
credentials: { credentials: {
accessKeyId: this.accessKeyId, accessKeyId: this.accessKeyId,
@@ -68,24 +68,34 @@ export class JDCloudAccess extends BaseAccess {
} }
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> { async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
const pager = new Pager(req); const pager = new Pager(req);
const service = await this.getJDDomainService(); const service = await this.getJDDomainService();
const domainRes = await service.describeDomains({ const domainRes = await this.catchCall(() => service.describeDomains({
domainName: req.searchKey, domainName: req.searchKey,
pageNumber: pager.pageNo, pageNumber: pager.pageNo,
pageSize: pager.pageSize, pageSize: pager.pageSize,
}) }))
let list = domainRes.result?.dataList || [] let list = domainRes.result?.dataList || []
list = list.map((item: any) => ({ list = list.map((item: any) => ({
id: item.domainId, id: item.domainId,
domain: item.domainName, domain: item.domainName,
})); }));
return { return {
total:domainRes.result.totalCount || list.length, total: domainRes.result.totalCount || list.length,
list, 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(); new JDCloudAccess();
@@ -8,7 +8,7 @@ import { JDCloudAccess } from "./access.js";
desc: "京东云DNS解析提供商", desc: "京东云DNS解析提供商",
accessType: "jdcloud", accessType: "jdcloud",
icon: "svg:icon-jdcloud", icon: "svg:icon-jdcloud",
order:3, order: 3,
}) })
export class JDCloudDnsProvider extends AbstractDnsProvider { export class JDCloudDnsProvider extends AbstractDnsProvider {
access!: JDCloudAccess; access!: JDCloudAccess;
@@ -36,8 +36,8 @@ export class JDCloudDnsProvider extends AbstractDnsProvider {
} }
const list = domainRes.result.dataList const list = domainRes.result.dataList
const found = list.find((item) => item.domainName === domain) const found = list.find((item) => item.domainName === domain)
if (!found){ if (!found) {
throw new Error(`域名${domain}在此京东云账号中不存在`) 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。 * weight Integer False 解析记录的权重,目前支持权重的有:A/AAAA/CNAME/JNAMEA/AAAA权重范围:0-100、CNAME/JNAME权重范围:1-100。
* viewValue Integer True 解析线路的ID,请调用describeViewTree接口获取基础解 * viewValue Integer True 解析线路的ID,请调用describeViewTree接口获取基础解
*/ */
try{ const res = await this.access.catchCall(() => service.createResourceRecord({
const res = await service.createResourceRecord({ domainId: domainId,
domainId: domainId, req: {
req:{ hostRecord: hostRecord,
hostRecord: hostRecord, hostValue: value,
hostValue: value, type: type,
type: type, ttl: 200,
ttl: 200, viewValue: -1,
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))
} }
throw e }))
} return {
recordId: res.result.dataList.id,
domainId: domainId
};
} }
async removeRecord(options: RemoveRecordOptions<any>): Promise<any> { async removeRecord(options: RemoveRecordOptions<any>): Promise<any> {
const record = options.recordRes; const record = options.recordRes;
const service = await this.getJDDomainService(); const service = await this.getJDDomainService();
await service.deleteResourceRecord({ await this.access.catchCall(() => service.deleteResourceRecord({
domainId: record.domainId, domainId: record.domainId,
resourceRecordId: record.recordId resourceRecordId: record.recordId
}) }))
} }
private async getJDDomainService() { private async getJDDomainService() {
return await this.access.getJDDomainService(); return await this.access.getJDDomainService();
} }
@@ -71,7 +71,7 @@ export class JDCloudDeployToCDN extends AbstractTaskPlugin {
this.logger.info(`开始上传证书`); this.logger.info(`开始上传证书`);
const sslService = await this.getSslClient(access); const sslService = await this.getSslClient(access);
const res = await sslService.uploadCert({ const res = await access.catchCall(() => sslService.uploadCert({
// certName String True 证书名称 // certName String True 证书名称
// keyFile String True 私钥 // keyFile String True 私钥
// certFile String True 证书 // certFile String True 证书
@@ -80,7 +80,7 @@ export class JDCloudDeployToCDN extends AbstractTaskPlugin {
keyFile: certInfo.key, keyFile: certInfo.key,
certFile: certInfo.crt, certFile: certInfo.crt,
aliasName: certName aliasName: certName
}); }));
certId = res.result.certId; certId = res.result.certId;
} }
@@ -152,10 +152,10 @@ export class JDCloudDeployToCDN extends AbstractTaskPlugin {
* pageNumber Integer False 1 pageNumber,默认值1 * pageNumber Integer False 1 pageNumber,默认值1
* pageSize * pageSize
*/ */
const res = await service.getDomainList({ const res = await access.catchCall(() => service.getDomainList({
pageNumber: 1, pageNumber: 1,
pageSize: 50 pageSize: 50
}); }));
// @ts-ignore // @ts-ignore
const list = res?.result?.domains; const list = res?.result?.domains;
if (!list || list.length === 0) { if (!list || list.length === 0) {
@@ -85,7 +85,7 @@ export class JDCloudUpdateCert extends AbstractTaskPlugin {
const certInfo = this.cert as CertInfo const certInfo = this.cert as CertInfo
for (const certId of this.certIds) { for (const certId of this.certIds) {
this.logger.info(`开始更新证书:${certId}`) 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
@param {string} opts.certId - 证书ID @param {string} opts.certId - 证书ID
@@ -96,7 +96,7 @@ export class JDCloudUpdateCert extends AbstractTaskPlugin {
certId, certId,
certFile: certInfo.crt, certFile: certInfo.crt,
keyFile:certInfo.key, keyFile:certInfo.key,
}) }))
this.logger.info(`更新证书${certId}成功:${JSON.stringify(res)}`); this.logger.info(`更新证书${certId}成功:${JSON.stringify(res)}`);
await this.ctx.utils.sleep(2000) await this.ctx.utils.sleep(2000)
} }
@@ -126,10 +126,10 @@ export class JDCloudUpdateCert extends AbstractTaskPlugin {
* pageNumber Integer False 1 pageNumber,默认值1 * pageNumber Integer False 1 pageNumber,默认值1
* pageSize * pageSize
*/ */
const res = await service.describeCerts({ const res = await access.catchCall(() => service.describeCerts({
pageNumber: 1, pageNumber: 1,
pageSize: 100, pageSize: 100,
}) }))
// @ts-ignore // @ts-ignore
const list = res?.result?.certListDetails const list = res?.result?.certListDetails
if (!list || list.length === 0) { if (!list || list.length === 0) {
@@ -61,7 +61,7 @@ export class JDCloudUploadCert extends AbstractTaskPlugin {
const service = await this.getClient(access); const service = await this.getClient(access);
const certInfo = this.cert as CertInfo; 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.certName - 证书名称
@param {string} opts.keyFile - 私钥 @param {string} opts.keyFile - 私钥
@@ -71,7 +71,7 @@ export class JDCloudUploadCert extends AbstractTaskPlugin {
certName: this.appendTimeSuffix(this.certName || "certd"), certName: this.appendTimeSuffix(this.certName || "certd"),
certFile: certInfo.crt, certFile: certInfo.crt,
keyFile: certInfo.key keyFile: certInfo.key
}); }));
this.jdcloudCertId = res.result.certId; this.jdcloudCertId = res.result.certId;
this.logger.info(`上传证书成功:${JSON.stringify(res)}`); this.logger.info(`上传证书成功:${JSON.stringify(res)}`);
} }