refactor: delete base64js

instead of base64 library you can use built-in JS functions `btoa()` and `atob()`
This commit is contained in:
Shishkevich D.
2025-03-07 07:11:03 +00:00
parent 2d8cca3a2e
commit 7483fb2ec5
5 changed files with 19 additions and 15 deletions
+2 -2
View File
@@ -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)
-11
View File
@@ -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';
+17
View File
@@ -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)
}
}