From 7483fb2ec57055f5f4f0fb14e559a87a5c2106f9 Mon Sep 17 00:00:00 2001 From: "Shishkevich D." <135337715+shishkevichd@users.noreply.github.com> Date: Fri, 7 Mar 2025 07:11:03 +0000 Subject: refactor: delete `base64js` instead of base64 library you can use built-in JS functions `btoa()` and `atob()` --- web/assets/js/model/inbound.js | 4 ++-- web/assets/js/util/common.js | 11 ----------- web/assets/js/util/utils.js | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 13 deletions(-) (limited to 'web/assets/js') diff --git a/web/assets/js/model/inbound.js b/web/assets/js/model/inbound.js index d3d7d297..49fc8a7b 100644 --- a/web/assets/js/model/inbound.js +++ b/web/assets/js/model/inbound.js @@ -1302,7 +1302,7 @@ class Inbound extends XrayCommonClass { } } - return 'vmess://' + base64(JSON.stringify(obj, null, 2)); + return 'vmess://' + Base64.encode(JSON.stringify(obj, null, 2)); } genVLESSLink(address = '', port = this.port, forceTls, remark = '', clientId, flow) { @@ -1474,7 +1474,7 @@ class Inbound extends XrayCommonClass { if (this.isSS2022) password.push(settings.password); if (this.isSSMultiUser) password.push(clientPassword); - let link = `ss://${safeBase64(settings.method + ':' + password.join(':'))}@${address}:${port}`; + let link = `ss://${Base64.encode(`${settings.method}:${password.join(':')}`, true)}@${address}:${port}`; const url = new URL(link); for (const [key, value] of params) { url.searchParams.set(key, value) diff --git a/web/assets/js/util/common.js b/web/assets/js/util/common.js index df826aa9..3aa1549e 100644 --- a/web/assets/js/util/common.js +++ b/web/assets/js/util/common.js @@ -39,17 +39,6 @@ function cpuCoreFormat(cores) { } } -function base64(str) { - return Base64.encode(str); -} - -function safeBase64(str) { - return base64(str) - .replace(/\+/g, '-') - .replace(/=/g, '') - .replace(/\//g, '_'); -} - function formatSecond(second) { if (second < 60) { return second.toFixed(0) + 's'; diff --git a/web/assets/js/util/utils.js b/web/assets/js/util/utils.js index 30f1f6a2..a79ce3a0 100644 --- a/web/assets/js/util/utils.js +++ b/web/assets/js/util/utils.js @@ -478,4 +478,21 @@ class Wireguard { privateKey: secretKey.length > 0 ? secretKey : this.keyToBase64(privateKey) }; } +} + +class Base64 { + static encode(content = "", safe = false) { + if (safe) { + return window.btoa(content) + .replace(/\+/g, '-') + .replace(/=/g, '') + .replace(/\//g, '_') + } + + return window.btoa(content) + } + + static decode(content = "") { + return window.atob(content) + } } \ No newline at end of file -- cgit v1.2.3