From d2a0fce7397e6d263c35db1f919e1c298f4dd06a Mon Sep 17 00:00:00 2001 From: WittF Date: Thu, 26 Jun 2025 05:43:48 +0800 Subject: [PATCH] refactor(captcha): remove Cap 1.x compatibility, keep only 2.x support --- public/locales/en-US/dashboard.json | 2 -- public/locales/ja-JP/dashboard.json | 2 -- public/locales/zh-CN/dashboard.json | 2 -- public/locales/zh-TW/dashboard.json | 2 -- src/api/site.ts | 1 - .../Admin/Settings/Captcha/CapCaptcha.tsx | 20 +------------------ src/component/Common/Captcha/CapCaptcha.tsx | 17 ++++------------ 7 files changed, 5 insertions(+), 41 deletions(-) diff --git a/public/locales/en-US/dashboard.json b/public/locales/en-US/dashboard.json index 16baa5f..5f3b9ee 100644 --- a/public/locales/en-US/dashboard.json +++ b/public/locales/en-US/dashboard.json @@ -437,8 +437,6 @@ "capKeyIDDes": "The key ID from your Cap server dashboard.", "capKeySecret": "Key Secret", "capKeySecretDes": "The key secret from your Cap server dashboard.", - "capVersion": "Cap Version", - "capVersionDes": "Select the version of your Cap server (1.x for legacy compatibility, 2.x for latest features).", "captchaProvider": "Captcha provider", "captchaWidth": "Width", "captchaHeight": "Height", diff --git a/public/locales/ja-JP/dashboard.json b/public/locales/ja-JP/dashboard.json index cf3393c..3ffa102 100644 --- a/public/locales/ja-JP/dashboard.json +++ b/public/locales/ja-JP/dashboard.json @@ -435,8 +435,6 @@ "capKeyIDDes": "Cap サーバーダッシュボードから取得したキー ID。", "capKeySecret": "キーシークレット", "capKeySecretDes": "Cap サーバーダッシュボードから取得したキーシークレット。", - "capVersion": "Cap バージョン", - "capVersionDes": "Cap サーバーのバージョンを選択してください(1.x は旧バージョン互換、2.x は最新機能)。", "captchaProvider": "認証コードタイプ", "captchaWidth": "幅", "captchaHeight": "高さ", diff --git a/public/locales/zh-CN/dashboard.json b/public/locales/zh-CN/dashboard.json index e5a1460..cba5119 100644 --- a/public/locales/zh-CN/dashboard.json +++ b/public/locales/zh-CN/dashboard.json @@ -435,8 +435,6 @@ "capKeyIDDes": "从 Cap 服务器控制面板获取的密钥 ID。", "capKeySecret": "密钥密码", "capKeySecretDes": "从 Cap 服务器控制面板获取的密钥密码。", - "capVersion": "Cap 版本", - "capVersionDes": "选择你的 Cap 服务器版本(1.x 用于兼容旧版本,2.x 为最新版本)。", "captchaProvider": "验证码类型", "captchaWidth": "宽度", "captchaHeight": "高度", diff --git a/public/locales/zh-TW/dashboard.json b/public/locales/zh-TW/dashboard.json index a3e2515..e25dc8f 100644 --- a/public/locales/zh-TW/dashboard.json +++ b/public/locales/zh-TW/dashboard.json @@ -432,8 +432,6 @@ "capKeyIDDes": "從 Cap 伺服器控制面板獲取的金鑰 ID。", "capKeySecret": "金鑰密碼", "capKeySecretDes": "從 Cap 伺服器控制面板獲取的金鑰密碼。", - "capVersion": "Cap 版本", - "capVersionDes": "選擇你的 Cap 伺服器版本(1.x 用於相容舊版本,2.x 為最新版本)。", "captchaProvider": "驗證碼型別", "captchaWidth": "寬度", "captchaHeight": "高度", diff --git a/src/api/site.ts b/src/api/site.ts index ed12332..aecb4fd 100644 --- a/src/api/site.ts +++ b/src/api/site.ts @@ -26,7 +26,6 @@ export interface SiteConfig { captcha_cap_instance_url?: string; captcha_cap_key_id?: string; captcha_cap_key_secret?: string; - captcha_cap_version?: 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 0055cc8..d6c27dd 100644 --- a/src/component/Admin/Settings/Captcha/CapCaptcha.tsx +++ b/src/component/Admin/Settings/Captcha/CapCaptcha.tsx @@ -1,5 +1,5 @@ import { Trans, useTranslation } from "react-i18next"; -import { FormControl, Link, Stack, MenuItem, Select, InputLabel } from "@mui/material"; +import { FormControl, Link, Stack } from "@mui/material"; import SettingForm from "../../../Pages/Setting/SettingForm.tsx"; import { DenseFilledTextField } from "../../../Common/StyledComponents.tsx"; import * as React from "react"; @@ -16,24 +16,6 @@ const CapCaptcha = ({ values, setSettings }: CapCaptchaProps) => { const { t } = useTranslation("dashboard"); return ( - - - {t("settings.capVersion")} - - {t("settings.capVersionDes")} - - state.siteConfig.basic.config.captcha_cap_instance_url); const capKeyID = useAppSelector((state) => state.siteConfig.basic.config.captcha_cap_key_id); - const capVersion = useAppSelector((state) => state.siteConfig.basic.config.captcha_cap_version); // Keep callback reference up to date useEffect(() => { @@ -89,16 +88,8 @@ const CapCaptcha = ({ onStateChange, generation, fullWidth, ...rest }: CapProps if (typeof window !== "undefined" && (window as any).Cap) { const widget = document.createElement("cap-widget"); - // Build API endpoint based on Cap version - let apiEndpoint; - if (capVersion === "1.x") { - // Version 1.x: {instanceURL}/api/{keyID}/ - apiEndpoint = `${capInstanceURL.replace(/\/$/, "")}/api/${capKeyID}/`; - } else { - // Version 2.x (default): {instanceURL}/{siteKey}/ - apiEndpoint = `${capInstanceURL.replace(/\/$/, "")}/${capKeyID}/`; - } - + // Cap 2.0 API format: {instanceURL}/{siteKey}/ + const apiEndpoint = `${capInstanceURL.replace(/\/$/, "")}/${capKeyID}/`; widget.setAttribute("data-cap-api-endpoint", apiEndpoint); widget.id = "cap-widget"; @@ -129,7 +120,7 @@ const CapCaptcha = ({ onStateChange, generation, fullWidth, ...rest }: CapProps if (generation > 0) { createWidget(); } - }, [generation, capVersion, t]); + }, [generation, t]); useEffect(() => { if (!capInstanceURL || !capKeyID) { @@ -175,7 +166,7 @@ const CapCaptcha = ({ onStateChange, generation, fullWidth, ...rest }: CapProps captchaRef.current.innerHTML = ""; } }; - }, [capInstanceURL, capKeyID, capVersion, t]); + }, [capInstanceURL, capKeyID, t]); if (!capInstanceURL || !capKeyID) { return null;