diff --git a/public/locales/en-US/dashboard.json b/public/locales/en-US/dashboard.json index 5f3b9ee..16baa5f 100644 --- a/public/locales/en-US/dashboard.json +++ b/public/locales/en-US/dashboard.json @@ -437,6 +437,8 @@ "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 3ffa102..cf3393c 100644 --- a/public/locales/ja-JP/dashboard.json +++ b/public/locales/ja-JP/dashboard.json @@ -435,6 +435,8 @@ "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 cba5119..e5a1460 100644 --- a/public/locales/zh-CN/dashboard.json +++ b/public/locales/zh-CN/dashboard.json @@ -435,6 +435,8 @@ "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 e25dc8f..a3e2515 100644 --- a/public/locales/zh-TW/dashboard.json +++ b/public/locales/zh-TW/dashboard.json @@ -432,6 +432,8 @@ "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 aecb4fd..ed12332 100644 --- a/src/api/site.ts +++ b/src/api/site.ts @@ -26,6 +26,7 @@ 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 d6c27dd..0055cc8 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 } from "@mui/material"; +import { FormControl, Link, Stack, MenuItem, Select, InputLabel } from "@mui/material"; import SettingForm from "../../../Pages/Setting/SettingForm.tsx"; import { DenseFilledTextField } from "../../../Common/StyledComponents.tsx"; import * as React from "react"; @@ -16,6 +16,24 @@ 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(() => { @@ -87,7 +88,18 @@ 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/`); + + // 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}/`; + } + + widget.setAttribute("data-cap-api-endpoint", apiEndpoint); widget.id = "cap-widget"; // Set internationalization attributes (Cap official i18n format) @@ -117,7 +129,7 @@ const CapCaptcha = ({ onStateChange, generation, fullWidth, ...rest }: CapProps if (generation > 0) { createWidget(); } - }, [generation, t]); + }, [generation, capVersion, t]); useEffect(() => { if (!capInstanceURL || !capKeyID) { @@ -163,7 +175,7 @@ const CapCaptcha = ({ onStateChange, generation, fullWidth, ...rest }: CapProps captchaRef.current.innerHTML = ""; } }; - }, [capInstanceURL, capKeyID, t]); + }, [capInstanceURL, capKeyID, capVersion, t]); if (!capInstanceURL || !capKeyID) { return null;