diff options
| author | Ho3ein <ho3ein.sanaei@gmail.com> | 2023-12-10 17:42:52 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-10 17:42:52 +0300 |
| commit | e3f1d3c892a1af48f27fdc36f273a55f38d13b40 (patch) | |
| tree | b11d0c1ed3c15c8f6f891a5e6df8e021d5db8ab6 /web/assets/js/model/dbinbound.js | |
| parent | 36cf7c0a8fda915b51e75958ce729fd9a61a5c90 (diff) | |
| parent | 9fbe80f87f950673058f0001b3704251fa8b9243 (diff) | |
huge changes
Diffstat (limited to 'web/assets/js/model/dbinbound.js')
| -rw-r--r-- | web/assets/js/model/dbinbound.js | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/web/assets/js/model/dbinbound.js b/web/assets/js/model/dbinbound.js new file mode 100644 index 00000000..a7157f49 --- /dev/null +++ b/web/assets/js/model/dbinbound.js @@ -0,0 +1,144 @@ +class DBInbound { + + constructor(data) { + this.id = 0; + this.userId = 0; + this.up = 0; + this.down = 0; + this.total = 0; + this.remark = ""; + this.enable = true; + this.expiryTime = 0; + + this.listen = ""; + this.port = 0; + this.protocol = ""; + this.settings = ""; + this.streamSettings = ""; + this.tag = ""; + this.sniffing = ""; + this.clientStats = "" + if (data == null) { + return; + } + ObjectUtil.cloneProps(this, data); + } + + get totalGB() { + return toFixed(this.total / ONE_GB, 2); + } + + set totalGB(gb) { + this.total = toFixed(gb * ONE_GB, 0); + } + + get isVMess() { + return this.protocol === Protocols.VMESS; + } + + get isVLess() { + return this.protocol === Protocols.VLESS; + } + + get isTrojan() { + return this.protocol === Protocols.TROJAN; + } + + get isSS() { + return this.protocol === Protocols.SHADOWSOCKS; + } + + get isSocks() { + return this.protocol === Protocols.SOCKS; + } + + get isHTTP() { + return this.protocol === Protocols.HTTP; + } + + get address() { + let address = location.hostname; + if (!ObjectUtil.isEmpty(this.listen) && this.listen !== "0.0.0.0") { + address = this.listen; + } + return address; + } + + get _expiryTime() { + if (this.expiryTime === 0) { + return null; + } + return moment(this.expiryTime); + } + + set _expiryTime(t) { + if (t == null) { + this.expiryTime = 0; + } else { + this.expiryTime = t.valueOf(); + } + } + + get isExpiry() { + return this.expiryTime < new Date().getTime(); + } + + toInbound() { + let settings = {}; + if (!ObjectUtil.isEmpty(this.settings)) { + settings = JSON.parse(this.settings); + } + + let streamSettings = {}; + if (!ObjectUtil.isEmpty(this.streamSettings)) { + streamSettings = JSON.parse(this.streamSettings); + } + + let sniffing = {}; + if (!ObjectUtil.isEmpty(this.sniffing)) { + sniffing = JSON.parse(this.sniffing); + } + + const config = { + port: this.port, + listen: this.listen, + protocol: this.protocol, + settings: settings, + streamSettings: streamSettings, + tag: this.tag, + sniffing: sniffing, + clientStats: this.clientStats, + }; + return Inbound.fromJson(config); + } + + isMultiUser() { + switch (this.protocol) { + case Protocols.VMESS: + case Protocols.VLESS: + case Protocols.TROJAN: + return true; + case Protocols.SHADOWSOCKS: + return this.toInbound().isSSMultiUser; + default: + return false; + } + } + + hasLink() { + switch (this.protocol) { + case Protocols.VMESS: + case Protocols.VLESS: + case Protocols.TROJAN: + case Protocols.SHADOWSOCKS: + return true; + default: + return false; + } + } + + genInboundLinks() { + const inbound = this.toInbound(); + return inbound.genInboundLinks(this.remark,remarkModel); + } +}
\ No newline at end of file |
