From f99da50d43ef48ffdc1ffcbb414ab2f29de3339c Mon Sep 17 00:00:00 2001 From: WittF Date: Thu, 26 Jun 2025 14:59:14 +0800 Subject: [PATCH] refactor(captcha): update Cap to 2.0.0 (#268) * refactor(captcha): update Cap to 2.0.0 * refactor(captcha): remove Cap 1.x compatibility, keep only 2.x support * feat(captcha): update Cap field names to Site Key and Secret Key * docs(captcha): update Cap documentation links to latest version * fix(captcha): update Cap field names in SettingsWrapper configuration --- public/locales/en-US/dashboard.json | 8 +++---- public/locales/ja-JP/dashboard.json | 8 +++---- public/locales/zh-CN/dashboard.json | 8 +++---- public/locales/zh-TW/dashboard.json | 8 +++---- src/api/site.ts | 4 ++-- .../Admin/Settings/Captcha/CapCaptcha.tsx | 22 +++++++++---------- src/component/Admin/Settings/Settings.tsx | 4 ++-- src/component/Common/Captcha/CapCaptcha.tsx | 15 ++++++++----- 8 files changed, 40 insertions(+), 37 deletions(-) diff --git a/public/locales/en-US/dashboard.json b/public/locales/en-US/dashboard.json index 5f3b9ee..e5103be 100644 --- a/public/locales/en-US/dashboard.json +++ b/public/locales/en-US/dashboard.json @@ -433,10 +433,10 @@ "cap": "Cap", "capInstanceURL": "Instance URL", "capInstanceURLDes": "The URL of your self-hosted Cap server. For more details, see the <0>standalone mode documentation.", - "capKeyID": "Key ID", - "capKeyIDDes": "The key ID from your Cap server dashboard.", - "capKeySecret": "Key Secret", - "capKeySecretDes": "The key secret from your Cap server dashboard.", + "capSiteKey": "Site Key", + "capSiteKeyDes": "The site key from your Cap server dashboard.", + "capSecretKey": "Secret Key", + "capSecretKeyDes": "The secret key from your Cap server dashboard.", "captchaProvider": "Captcha provider", "captchaWidth": "Width", "captchaHeight": "Height", diff --git a/public/locales/ja-JP/dashboard.json b/public/locales/ja-JP/dashboard.json index 3ffa102..6664f46 100644 --- a/public/locales/ja-JP/dashboard.json +++ b/public/locales/ja-JP/dashboard.json @@ -431,10 +431,10 @@ "cap": "Cap", "capInstanceURL": "インスタンス URL", "capInstanceURLDes": "自身でホストしている Cap サーバーの URL。詳細については、<0>スタンドアロンモードドキュメント を参照してください。", - "capKeyID": "キー ID", - "capKeyIDDes": "Cap サーバーダッシュボードから取得したキー ID。", - "capKeySecret": "キーシークレット", - "capKeySecretDes": "Cap サーバーダッシュボードから取得したキーシークレット。", + "capSiteKey": "サイトキー", + "capSiteKeyDes": "Cap サーバーダッシュボードから取得したサイトキー。", + "capSecretKey": "シークレットキー", + "capSecretKeyDes": "Cap サーバーダッシュボードから取得したシークレットキー。", "captchaProvider": "認証コードタイプ", "captchaWidth": "幅", "captchaHeight": "高さ", diff --git a/public/locales/zh-CN/dashboard.json b/public/locales/zh-CN/dashboard.json index cba5119..05440e7 100644 --- a/public/locales/zh-CN/dashboard.json +++ b/public/locales/zh-CN/dashboard.json @@ -431,10 +431,10 @@ "cap": "Cap", "capInstanceURL": "实例 URL", "capInstanceURLDes": "自部署 Cap 服务器的 URL 地址。详细信息请参考 <0>独立模式文档。", - "capKeyID": "密钥 ID", - "capKeyIDDes": "从 Cap 服务器控制面板获取的密钥 ID。", - "capKeySecret": "密钥密码", - "capKeySecretDes": "从 Cap 服务器控制面板获取的密钥密码。", + "capSiteKey": "站点密钥", + "capSiteKeyDes": "从 Cap 服务器控制面板获取的站点密钥。", + "capSecretKey": "私密密钥", + "capSecretKeyDes": "从 Cap 服务器控制面板获取的私密密钥。", "captchaProvider": "验证码类型", "captchaWidth": "宽度", "captchaHeight": "高度", diff --git a/public/locales/zh-TW/dashboard.json b/public/locales/zh-TW/dashboard.json index e25dc8f..c2265b6 100644 --- a/public/locales/zh-TW/dashboard.json +++ b/public/locales/zh-TW/dashboard.json @@ -428,10 +428,10 @@ "cap": "Cap", "capInstanceURL": "實例 URL", "capInstanceURLDes": "自部署 Cap 伺服器的 URL 地址。詳細資訊請參考 <0>獨立模式文檔。", - "capKeyID": "金鑰 ID", - "capKeyIDDes": "從 Cap 伺服器控制面板獲取的金鑰 ID。", - "capKeySecret": "金鑰密碼", - "capKeySecretDes": "從 Cap 伺服器控制面板獲取的金鑰密碼。", + "capSiteKey": "站點金鑰", + "capSiteKeyDes": "從 Cap 伺服器控制面板獲取的站點金鑰。", + "capSecretKey": "私密金鑰", + "capSecretKeyDes": "從 Cap 伺服器控制面板獲取的私密金鑰。", "captchaProvider": "驗證碼型別", "captchaWidth": "寬度", "captchaHeight": "高度", diff --git a/src/api/site.ts b/src/api/site.ts index aecb4fd..dbd8ba4 100644 --- a/src/api/site.ts +++ b/src/api/site.ts @@ -24,8 +24,8 @@ export interface SiteConfig { captcha_type?: CaptchaType; turnstile_site_id?: string; captcha_cap_instance_url?: string; - captcha_cap_key_id?: string; - captcha_cap_key_secret?: string; + captcha_cap_site_key?: string; + captcha_cap_secret_key?: string; register_enabled?: boolean; logo?: string; logo_light?: string; diff --git a/src/component/Admin/Settings/Captcha/CapCaptcha.tsx b/src/component/Admin/Settings/Captcha/CapCaptcha.tsx index d6c27dd..907e15b 100644 --- a/src/component/Admin/Settings/Captcha/CapCaptcha.tsx +++ b/src/component/Admin/Settings/Captcha/CapCaptcha.tsx @@ -32,38 +32,38 @@ const CapCaptcha = ({ values, setSettings }: CapCaptchaProps) => { ]} + components={[]} /> - + setSettings({ - captcha_cap_key_id: e.target.value, + captcha_cap_site_key: e.target.value, }) } required /> ]} + components={[]} /> - + setSettings({ - captcha_cap_key_secret: e.target.value, + captcha_cap_secret_key: e.target.value, }) } type="password" @@ -71,9 +71,9 @@ const CapCaptcha = ({ values, setSettings }: CapCaptchaProps) => { /> ]} + components={[]} /> diff --git a/src/component/Admin/Settings/Settings.tsx b/src/component/Admin/Settings/Settings.tsx index ee07f15..f054862 100644 --- a/src/component/Admin/Settings/Settings.tsx +++ b/src/component/Admin/Settings/Settings.tsx @@ -222,8 +222,8 @@ const Settings = () => { "captcha_turnstile_site_key", "captcha_turnstile_site_secret", "captcha_cap_instance_url", - "captcha_cap_key_id", - "captcha_cap_key_secret", + "captcha_cap_site_key", + "captcha_cap_secret_key", ]} > diff --git a/src/component/Common/Captcha/CapCaptcha.tsx b/src/component/Common/Captcha/CapCaptcha.tsx index 2f4d87a..6787d8e 100644 --- a/src/component/Common/Captcha/CapCaptcha.tsx +++ b/src/component/Common/Captcha/CapCaptcha.tsx @@ -21,7 +21,7 @@ const CapCaptcha = ({ onStateChange, generation, fullWidth, ...rest }: CapProps const { t } = useTranslation("common"); const capInstanceURL = useAppSelector((state) => state.siteConfig.basic.config.captcha_cap_instance_url); - const capKeyID = useAppSelector((state) => state.siteConfig.basic.config.captcha_cap_key_id); + const capSiteKey = useAppSelector((state) => state.siteConfig.basic.config.captcha_cap_site_key); // Keep callback reference up to date useEffect(() => { @@ -72,7 +72,7 @@ const CapCaptcha = ({ onStateChange, generation, fullWidth, ...rest }: CapProps }; const createWidget = () => { - if (!captchaRef.current || !capInstanceURL || !capKeyID) { + if (!captchaRef.current || !capInstanceURL || !capSiteKey) { return; } @@ -87,7 +87,10 @@ const CapCaptcha = ({ onStateChange, generation, fullWidth, ...rest }: CapProps if (typeof window !== "undefined" && (window as any).Cap) { const widget = document.createElement("cap-widget"); - widget.setAttribute("data-cap-api-endpoint", `${capInstanceURL.replace(/\/$/, "")}/${capKeyID}/api/`); + + // Cap 2.0 API format: {instanceURL}/{siteKey}/ + const apiEndpoint = `${capInstanceURL.replace(/\/$/, "")}/${capSiteKey}/`; + widget.setAttribute("data-cap-api-endpoint", apiEndpoint); widget.id = "cap-widget"; // Set internationalization attributes (Cap official i18n format) @@ -120,7 +123,7 @@ const CapCaptcha = ({ onStateChange, generation, fullWidth, ...rest }: CapProps }, [generation, t]); useEffect(() => { - if (!capInstanceURL || !capKeyID) { + if (!capInstanceURL || !capSiteKey) { return; } @@ -163,9 +166,9 @@ const CapCaptcha = ({ onStateChange, generation, fullWidth, ...rest }: CapProps captchaRef.current.innerHTML = ""; } }; - }, [capInstanceURL, capKeyID, t]); + }, [capInstanceURL, capSiteKey, t]); - if (!capInstanceURL || !capKeyID) { + if (!capInstanceURL || !capSiteKey) { return null; }