mirror of
https://github.com/cloudreve/frontend.git
synced 2025-12-25 19:52:48 +00:00
refactor(captcha): update Cap to 2.0.0
This commit is contained in:
parent
39ee23ca8f
commit
afdbd97c7b
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -435,6 +435,8 @@
|
|||
"capKeyIDDes": "Cap サーバーダッシュボードから取得したキー ID。",
|
||||
"capKeySecret": "キーシークレット",
|
||||
"capKeySecretDes": "Cap サーバーダッシュボードから取得したキーシークレット。",
|
||||
"capVersion": "Cap バージョン",
|
||||
"capVersionDes": "Cap サーバーのバージョンを選択してください(1.x は旧バージョン互換、2.x は最新機能)。",
|
||||
"captchaProvider": "認証コードタイプ",
|
||||
"captchaWidth": "幅",
|
||||
"captchaHeight": "高さ",
|
||||
|
|
|
|||
|
|
@ -435,6 +435,8 @@
|
|||
"capKeyIDDes": "从 Cap 服务器控制面板获取的密钥 ID。",
|
||||
"capKeySecret": "密钥密码",
|
||||
"capKeySecretDes": "从 Cap 服务器控制面板获取的密钥密码。",
|
||||
"capVersion": "Cap 版本",
|
||||
"capVersionDes": "选择你的 Cap 服务器版本(1.x 用于兼容旧版本,2.x 为最新版本)。",
|
||||
"captchaProvider": "验证码类型",
|
||||
"captchaWidth": "宽度",
|
||||
"captchaHeight": "高度",
|
||||
|
|
|
|||
|
|
@ -432,6 +432,8 @@
|
|||
"capKeyIDDes": "從 Cap 伺服器控制面板獲取的金鑰 ID。",
|
||||
"capKeySecret": "金鑰密碼",
|
||||
"capKeySecretDes": "從 Cap 伺服器控制面板獲取的金鑰密碼。",
|
||||
"capVersion": "Cap 版本",
|
||||
"capVersionDes": "選擇你的 Cap 伺服器版本(1.x 用於相容舊版本,2.x 為最新版本)。",
|
||||
"captchaProvider": "驗證碼型別",
|
||||
"captchaWidth": "寬度",
|
||||
"captchaHeight": "高度",
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<Stack spacing={3}>
|
||||
<SettingForm title={t("settings.capVersion")} lgWidth={5}>
|
||||
<FormControl fullWidth>
|
||||
<InputLabel>{t("settings.capVersion")}</InputLabel>
|
||||
<Select
|
||||
value={values.captcha_cap_version || "1.x"}
|
||||
onChange={(e) =>
|
||||
setSettings({
|
||||
captcha_cap_version: e.target.value,
|
||||
})
|
||||
}
|
||||
label={t("settings.capVersion")}
|
||||
>
|
||||
<MenuItem value="1.x">1.x (Legacy)</MenuItem>
|
||||
<MenuItem value="2.x">2.x (Latest)</MenuItem>
|
||||
</Select>
|
||||
<NoMarginHelperText>{t("settings.capVersionDes")}</NoMarginHelperText>
|
||||
</FormControl>
|
||||
</SettingForm>
|
||||
<SettingForm title={t("settings.capInstanceURL")} lgWidth={5}>
|
||||
<FormControl fullWidth>
|
||||
<DenseFilledTextField
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ const CapCaptcha = ({ onStateChange, generation, fullWidth, ...rest }: CapProps
|
|||
|
||||
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 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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue