perf: 优化acme sdk

This commit is contained in:
xiaojunnuo
2025-01-03 01:17:20 +08:00
parent 03b751fa13
commit 54db744282
6 changed files with 94 additions and 97 deletions
+6 -23
View File
@@ -99,31 +99,14 @@ export default async (client, userOpts) => {
return;
}
const keyAuthorizationGetter = async (challenge) => {
return await client.getChallengeKeyAuthorization(challenge);
}
try {
/* Select challenge based on priority */
const challenge = authz.challenges.sort((a, b) => {
const aidx = opts.challengePriority.indexOf(a.type);
const bidx = opts.challengePriority.indexOf(b.type);
if (aidx === -1) return 1;
if (bidx === -1) return -1;
return aidx - bidx;
}).slice(0, 1)[0];
if (!challenge) {
throw new Error(`Unable to select challenge for ${d}, no challenge found`);
}
log(`[auto] [${d}] Found ${authz.challenges.length} challenges, selected type: ${challenge.type}`);
/* Trigger challengeCreateFn() */
log(`[auto] [${d}] Trigger challengeCreateFn()`);
const keyAuthorization = await client.getChallengeKeyAuthorization(challenge);
try {
const { recordReq, recordRes, dnsProvider } = await opts.challengeCreateFn(authz, challenge, keyAuthorization);
log(`[auto] [${d}] challengeCreateFn success`);
log(`[auto] [${d}] add challengeRemoveFn()`);
const { recordReq, recordRes, dnsProvider,challenge ,keyAuthorization} = await opts.challengeCreateFn(authz, keyAuthorizationGetter);
clearTasks.push(async () => {
/* Trigger challengeRemoveFn(), suppress errors */
log(`[auto] [${d}] Trigger challengeRemoveFn()`);
@@ -141,7 +124,7 @@ export default async (client, userOpts) => {
await wait(60 * 1000);
}
else {
log(`[auto] [${d}] Running challenge verification`);
log(`[auto] [${d}] Running challenge verification, type = ${challenge.type}`);
try {
await client.verifyChallenge(authz, challenge);
}
+2
View File
@@ -5,3 +5,5 @@ export class CancelError extends Error {
}
}