mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-07-31 20:32:23 +03:00
Ports the framework-agnostic JS from web/assets/js/ into frontend/src/
so Vue 3 pages can import what they need without relying on script-tag
globals.
- web/assets/js/util/index.js (927 lines, 21 classes) →
frontend/src/utils/legacy.js + a barrel at utils/index.js. All
classes are now named exports.
- Vue.prototype.$message in HttpUtil → direct import of `message`
from ant-design-vue (Vue 3 has no Vue.prototype).
- RandomUtil.randomShadowsocksPassword previously defaulted to
SSMethods.BLAKE3_AES_256_GCM from inbound.js, creating a circular
import. Replaced with the literal string default.
- MediaQueryMixin (Vue 2 mixin) removed. Replaced by
composables/useMediaQuery.js — Vue 3 composable returning reactive
`isMobile`.
- axios-init.js wrapped as setupAxios(); Qs global → npm `qs`.
- websocket.js exported as WebSocketClient class; the implicit
window.wsClient global is gone — pages instantiate it themselves.
- model/{inbound,outbound,dbinbound,setting,reality_targets}.js
copied with `export` added on every top-level declaration. Imports
between models and utils are wired up explicitly.
- subscription.js deferred to Phase 5 (it's a Vue 2 mount, not a util).
- App.vue smoke test exercises SizeFormatter / RandomUtil / Wireguard /
useMediaQuery so the user can verify Phase 3 with `npm run dev`.
Run `cd frontend && npm install && npm run dev` — qs was added so a
fresh install is required.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
179 lines
4.4 KiB
JavaScript
179 lines
4.4 KiB
JavaScript
import { ObjectUtil, NumberFormatter, SizeFormatter } from '../utils/legacy.js';
|
|
import { Inbound, Protocols } from './inbound.js';
|
|
|
|
export class DBInbound {
|
|
|
|
constructor(data) {
|
|
this.id = 0;
|
|
this.userId = 0;
|
|
this.up = 0;
|
|
this.down = 0;
|
|
this.total = 0;
|
|
this.allTime = 0;
|
|
this.remark = "";
|
|
this.enable = true;
|
|
this.expiryTime = 0;
|
|
this.trafficReset = "never";
|
|
this.lastTrafficResetTime = 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 NumberFormatter.toFixed(this.total / SizeFormatter.ONE_GB, 2);
|
|
}
|
|
|
|
set totalGB(gb) {
|
|
this.total = NumberFormatter.toFixed(gb * SizeFormatter.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 isMixed() {
|
|
return this.protocol === Protocols.MIXED;
|
|
}
|
|
|
|
get isHTTP() {
|
|
return this.protocol === Protocols.HTTP;
|
|
}
|
|
|
|
get isWireguard() {
|
|
return this.protocol === Protocols.WIREGUARD;
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
invalidateCache() {
|
|
this._cachedInbound = null;
|
|
this._clientStatsMap = null;
|
|
}
|
|
|
|
toInbound() {
|
|
if (this._cachedInbound) {
|
|
return this._cachedInbound;
|
|
}
|
|
|
|
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,
|
|
};
|
|
|
|
this._cachedInbound = Inbound.fromJson(config);
|
|
return this._cachedInbound;
|
|
}
|
|
|
|
getClientStats(email) {
|
|
if (!this._clientStatsMap) {
|
|
this._clientStatsMap = new Map();
|
|
if (this.clientStats && Array.isArray(this.clientStats)) {
|
|
for (const stats of this.clientStats) {
|
|
this._clientStatsMap.set(stats.email, stats);
|
|
}
|
|
}
|
|
}
|
|
return this._clientStatsMap.get(email);
|
|
}
|
|
|
|
isMultiUser() {
|
|
switch (this.protocol) {
|
|
case Protocols.VMESS:
|
|
case Protocols.VLESS:
|
|
case Protocols.TROJAN:
|
|
case Protocols.HYSTERIA:
|
|
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:
|
|
case Protocols.HYSTERIA:
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
genInboundLinks(remarkModel) {
|
|
const inbound = this.toInbound();
|
|
return inbound.genInboundLinks(this.remark, remarkModel);
|
|
}
|
|
} |