mirror of
https://github.com/cloudreve/frontend.git
synced 2025-12-26 04:02:47 +00:00
feat(captcha): Update static asset server option to support unpkg CDN
This commit is contained in:
parent
b768bb1410
commit
abae484156
|
|
@ -439,7 +439,8 @@
|
|||
"capSecretKeyDes": "The secret key from your Cap server dashboard.",
|
||||
"capAssetServer": "Asset Server Source",
|
||||
"capAssetServerDes": "Choose the source for loading Cap captcha static assets. Using self-deployed server requires setting ENABLE_ASSETS_SERVER=true environment variable to <0>enable asset server</0>.",
|
||||
"capAssetServerCdn": "Default public CDN",
|
||||
"capAssetServerJsdelivr": "jsDelivr CDN",
|
||||
"capAssetServerUnpkg": "unpkg CDN",
|
||||
"capAssetServerInstance": "Self-deployed server",
|
||||
"captchaProvider": "Captcha provider",
|
||||
"captchaWidth": "Width",
|
||||
|
|
|
|||
|
|
@ -437,7 +437,8 @@
|
|||
"capSecretKeyDes": "Cap サーバーダッシュボードから取得したシークレットキー。",
|
||||
"capAssetServer": "静的リソースソース",
|
||||
"capAssetServerDes": "Cap認証コードの静的リソースの読み込みソースを選択します。自己デプロイサーバーを使用するにはサーバー側で環境変数 ENABLE_ASSETS_SERVER=true を設定して<0>静的リソースサービスを有効にする</0>必要があります。",
|
||||
"capAssetServerCdn": "デフォルト公共CDN",
|
||||
"capAssetServerJsdelivr": "jsDelivr CDN",
|
||||
"capAssetServerUnpkg": "unpkg CDN",
|
||||
"capAssetServerInstance": "自己デプロイサーバー",
|
||||
"captchaProvider": "認証コードタイプ",
|
||||
"captchaWidth": "幅",
|
||||
|
|
|
|||
|
|
@ -437,7 +437,8 @@
|
|||
"capSecretKeyDes": "从 Cap 服务器控制面板获取的私密密钥。",
|
||||
"capAssetServer": "静态资源服务源",
|
||||
"capAssetServerDes": "选择 Cap 验证码静态资源的加载源。使用自部署服务器需要在服务器端设置环境变量 ENABLE_ASSETS_SERVER=true <0>开启静态资源服务</0>。",
|
||||
"capAssetServerCdn": "默认境外 CDN",
|
||||
"capAssetServerJsdelivr": "jsDelivr CDN",
|
||||
"capAssetServerUnpkg": "unpkg CDN",
|
||||
"capAssetServerInstance": "自部署服务器",
|
||||
"captchaProvider": "验证码类型",
|
||||
"captchaWidth": "宽度",
|
||||
|
|
|
|||
|
|
@ -434,7 +434,8 @@
|
|||
"capSecretKeyDes": "從 Cap 伺服器控制面板獲取的私密金鑰。",
|
||||
"capAssetServer": "靜態資源服務源",
|
||||
"capAssetServerDes": "選擇 Cap 驗證碼靜態資源的載入源。使用自部署伺服器需要在伺服器端設定環境變數 ENABLE_ASSETS_SERVER=true <0>開啟靜態資源服務</0>。",
|
||||
"capAssetServerCdn": "預設公共 CDN",
|
||||
"capAssetServerJsdelivr": "jsDelivr CDN",
|
||||
"capAssetServerUnpkg": "unpkg CDN",
|
||||
"capAssetServerInstance": "自部署伺服器",
|
||||
"captchaProvider": "驗證碼型別",
|
||||
"captchaWidth": "寬度",
|
||||
|
|
|
|||
|
|
@ -82,20 +82,29 @@ const CapCaptcha = ({ values, setSettings }: CapCaptchaProps) => {
|
|||
<SettingForm title={t("settings.capAssetServer")} lgWidth={5}>
|
||||
<FormControl>
|
||||
<DenseSelect
|
||||
value={values.captcha_cap_asset_server || "cdn"}
|
||||
value={values.captcha_cap_asset_server || "jsdelivr"}
|
||||
onChange={(e) =>
|
||||
setSettings({
|
||||
captcha_cap_asset_server: e.target.value,
|
||||
})
|
||||
}
|
||||
>
|
||||
<SquareMenuItem value="cdn">
|
||||
<SquareMenuItem value="jsdelivr">
|
||||
<ListItemText
|
||||
slotProps={{
|
||||
primary: { variant: "body2" },
|
||||
}}
|
||||
>
|
||||
{t("settings.capAssetServerCdn")}
|
||||
{t("settings.capAssetServerJsdelivr")}
|
||||
</ListItemText>
|
||||
</SquareMenuItem>
|
||||
<SquareMenuItem value="unpkg">
|
||||
<ListItemText
|
||||
slotProps={{
|
||||
primary: { variant: "body2" },
|
||||
}}
|
||||
>
|
||||
{t("settings.capAssetServerUnpkg")}
|
||||
</ListItemText>
|
||||
</SquareMenuItem>
|
||||
<SquareMenuItem value="instance">
|
||||
|
|
|
|||
|
|
@ -136,9 +136,12 @@ const CapCaptcha = ({ onStateChange, generation, fullWidth, ...rest }: CapProps
|
|||
|
||||
// 根据配置设置WASM URL,保持资源加载的一致性
|
||||
if (capAssetServer === "instance") {
|
||||
(window as any).CAP_CUSTOM_WASM_URL = `${capInstanceURL.replace(/\/$/, "")}/assets/cap_wasm_bg.wasm`;
|
||||
(window as any).CAP_CUSTOM_WASM_URL = `${capInstanceURL.replace(/\/$/, "")}/assets/cap_wasm.min.js`;
|
||||
} else if (capAssetServer === "unpkg") {
|
||||
(window as any).CAP_CUSTOM_WASM_URL = "https://unpkg.com/@cap.js/wasm@0.0.4/browser/cap_wasm.js";
|
||||
} else {
|
||||
(window as any).CAP_CUSTOM_WASM_URL = "https://cdn.jsdelivr.net/npm/@captcha/widget/dist/cap_wasm_bg.wasm";
|
||||
// jsdelivr - 默认CDN
|
||||
(window as any).CAP_CUSTOM_WASM_URL = "https://cdn.jsdelivr.net/npm/@cap.js/wasm@0.0.4/browser/cap_wasm.min.js";
|
||||
}
|
||||
|
||||
// Add a small delay to ensure DOM is ready
|
||||
|
|
@ -152,10 +155,15 @@ const CapCaptcha = ({ onStateChange, generation, fullWidth, ...rest }: CapProps
|
|||
script.id = scriptId;
|
||||
|
||||
// 根据配置选择静态资源源
|
||||
const assetSource =
|
||||
capAssetServer === "instance"
|
||||
? `${capInstanceURL.replace(/\/$/, "")}/assets/widget.js`
|
||||
: "https://cdn.jsdelivr.net/npm/@captcha/widget/dist/widget.js";
|
||||
let assetSource;
|
||||
if (capAssetServer === "instance") {
|
||||
assetSource = `${capInstanceURL.replace(/\/$/, "")}/assets/widget.js`;
|
||||
} else if (capAssetServer === "unpkg") {
|
||||
assetSource = "https://unpkg.com/@cap.js/widget";
|
||||
} else {
|
||||
// jsdelivr - 默认CDN
|
||||
assetSource = "https://cdn.jsdelivr.net/npm/@cap.js/widget";
|
||||
}
|
||||
|
||||
script.src = assetSource;
|
||||
script.async = true;
|
||||
|
|
@ -163,6 +171,8 @@ const CapCaptcha = ({ onStateChange, generation, fullWidth, ...rest }: CapProps
|
|||
script.onerror = () => {
|
||||
if (capAssetServer === "instance") {
|
||||
console.error("Failed to load Cap widget script from instance server");
|
||||
} else if (capAssetServer === "unpkg") {
|
||||
console.error("Failed to load Cap widget script from unpkg CDN");
|
||||
} else {
|
||||
console.error("Failed to load Cap widget script from jsDelivr CDN");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue