Skip to content

Commit 7483fb2

Browse files
committed
refactor: delete base64js
instead of base64 library you can use built-in JS functions `btoa()` and `atob()`
1 parent 2d8cca3 commit 7483fb2

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

web/assets/base64/base64.min.js

-1
This file was deleted.

web/assets/js/model/inbound.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ class Inbound extends XrayCommonClass {
13021302
}
13031303
}
13041304

1305-
return 'vmess://' + base64(JSON.stringify(obj, null, 2));
1305+
return 'vmess://' + Base64.encode(JSON.stringify(obj, null, 2));
13061306
}
13071307

13081308
genVLESSLink(address = '', port = this.port, forceTls, remark = '', clientId, flow) {
@@ -1474,7 +1474,7 @@ class Inbound extends XrayCommonClass {
14741474
if (this.isSS2022) password.push(settings.password);
14751475
if (this.isSSMultiUser) password.push(clientPassword);
14761476

1477-
let link = `ss://${safeBase64(settings.method + ':' + password.join(':'))}@${address}:${port}`;
1477+
let link = `ss://${Base64.encode(`${settings.method}:${password.join(':')}`, true)}@${address}:${port}`;
14781478
const url = new URL(link);
14791479
for (const [key, value] of params) {
14801480
url.searchParams.set(key, value)

web/assets/js/util/common.js

-11
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,6 @@ function cpuCoreFormat(cores) {
3939
}
4040
}
4141

42-
function base64(str) {
43-
return Base64.encode(str);
44-
}
45-
46-
function safeBase64(str) {
47-
return base64(str)
48-
.replace(/\+/g, '-')
49-
.replace(/=/g, '')
50-
.replace(/\//g, '_');
51-
}
52-
5342
function formatSecond(second) {
5443
if (second < 60) {
5544
return second.toFixed(0) + 's';

web/assets/js/util/utils.js

+17
Original file line numberDiff line numberDiff line change
@@ -478,4 +478,21 @@ class Wireguard {
478478
privateKey: secretKey.length > 0 ? secretKey : this.keyToBase64(privateKey)
479479
};
480480
}
481+
}
482+
483+
class Base64 {
484+
static encode(content = "", safe = false) {
485+
if (safe) {
486+
return window.btoa(content)
487+
.replace(/\+/g, '-')
488+
.replace(/=/g, '')
489+
.replace(/\//g, '_')
490+
}
491+
492+
return window.btoa(content)
493+
}
494+
495+
static decode(content = "") {
496+
return window.atob(content)
497+
}
481498
}

web/html/xui/inbounds.html

-1
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,6 @@
544544
</a-layout>
545545
</a-layout>
546546
{{template "js" .}}
547-
<script src="{{ .base_path }}assets/base64/base64.min.js"></script>
548547
<script src="{{ .base_path }}assets/qrcode/qrious2.min.js?{{ .cur_ver }}"></script>
549548
<script src="{{ .base_path }}assets/uri/URI.min.js?{{ .cur_ver }}"></script>
550549
<script src="{{ .base_path }}assets/js/model/inbound.js?{{ .cur_ver }}"></script>

0 commit comments

Comments
 (0)