From e31d26a8871c6088d9f8c0f580746ff2a810ae0c Mon Sep 17 00:00:00 2001 From: Zero Clover <13190004+ZeroClover@users.noreply.github.com> Date: Fri, 19 Sep 2025 17:36:29 +0800 Subject: [PATCH] perf: add preferred chain for google trust service (#539) @ZeroClover --- .../src/plugin/cert-plugin/index.ts | 63 +++++++++++++++---- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/packages/plugins/plugin-cert/src/plugin/cert-plugin/index.ts b/packages/plugins/plugin-cert/src/plugin/cert-plugin/index.ts index d7d268fb..6171ba2f 100644 --- a/packages/plugins/plugin-cert/src/plugin/cert-plugin/index.ts +++ b/packages/plugins/plugin-cert/src/plugin/cert-plugin/index.ts @@ -38,6 +38,53 @@ export type DomainsVerifyPlanInput = { [key: string]: DomainVerifyPlanInput; }; +const preferredChainConfigs = { + letsencrypt: { + helper: "如无特殊需求保持默认即可", + options: [ + { value: "ISRG Root X1", label: "ISRG Root X1" }, + { value: "ISRG Root X2", label: "ISRG Root X2" }, + ], + }, + google: { + helper: "GlobalSign 提供对老旧设备更好的兼容性,但证书链会变长", + options: [ + { value: "GTS Root R1", label: "GTS Root R1" }, + { value: "GlobalSign", label: "GlobalSign" }, + ], + }, +} as const; + +const preferredChainSupportedProviders = Object.keys(preferredChainConfigs); + +const preferredChainMergeScript = (() => { + const configs = JSON.stringify(preferredChainConfigs); + const supportedProviders = JSON.stringify(preferredChainSupportedProviders); + const defaultProvider = JSON.stringify(preferredChainSupportedProviders[0]); + return ` + const chainConfigs = ${configs}; + const supportedProviders = ${supportedProviders}; + const defaultProvider = ${defaultProvider}; + const getConfig = (provider)=> chainConfigs[provider] || chainConfigs[defaultProvider]; + return { + show: ctx.compute(({form})=> supportedProviders.includes(form.sslProvider)), + component: { + options: ctx.compute(({form})=> getConfig(form.sslProvider).options) + }, + helper: ctx.compute(({form})=> getConfig(form.sslProvider).helper), + value: ctx.compute(({form})=>{ + const { options } = getConfig(form.sslProvider); + const allowed = options.map(item=>item.value); + const current = form.preferredChain; + if(allowed.includes(current)){ + return current; + } + return allowed[0]; + }) + }; + `; +})(); + @IsTaskPlugin({ name: "CertApply", title: "证书申请(JS版)", @@ -294,24 +341,14 @@ export class CertApplyPlugin extends CertApplyBasePlugin { @TaskInput({ title: "首选链", - value: "ISRG Root X1", component: { name: "a-select", vModel: "value", - options: [ - { value: "ISRG Root X1", label: "ISRG Root X1" }, - { value: "ISRG Root X2", label: "ISRG Root X2" }, - ], + options: preferredChainConfigs.letsencrypt.options, }, - helper: "仅 Let's Encrypt 可选,默认为 ISRG Root X1", + helper: preferredChainConfigs.letsencrypt.helper, required: false, - mergeScript: ` - return { - show: ctx.compute(({form})=>{ - return form.sslProvider === 'letsencrypt' - }) - } - `, + mergeScript: preferredChainMergeScript, }) preferredChain!: string;