mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-07-01 20:42:07 +00:00
optimized finding client index
Co-Authored-By: Alireza Ahmadi <alireza7@gmail.com>
This commit is contained in:
parent
9c231a41d1
commit
6aeedac051
1 changed files with 9 additions and 5 deletions
|
@ -711,7 +711,7 @@
|
||||||
openEditClient(dbInboundId, client) {
|
openEditClient(dbInboundId, client) {
|
||||||
dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
|
dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
|
||||||
clients = this.getInboundClients(dbInbound);
|
clients = this.getInboundClients(dbInbound);
|
||||||
index = this.findIndexOfClient(clients, client);
|
index = this.findIndexOfClient(dbInbound.protocol, clients, client);
|
||||||
clientModal.show({
|
clientModal.show({
|
||||||
title: '{{ i18n "pages.client.edit"}}',
|
title: '{{ i18n "pages.client.edit"}}',
|
||||||
okText: '{{ i18n "pages.client.submitEdit"}}',
|
okText: '{{ i18n "pages.client.submitEdit"}}',
|
||||||
|
@ -725,8 +725,13 @@
|
||||||
isEdit: true
|
isEdit: true
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
findIndexOfClient(clients, client) {
|
findIndexOfClient(protocol, clients, client) {
|
||||||
return clients.findIndex(item => JSON.stringify(item) === JSON.stringify(client));
|
switch (protocol) {
|
||||||
|
case Protocols.TROJAN:
|
||||||
|
case Protocols.SHADOWSOCKS:
|
||||||
|
return clients.findIndex(item => item.password === client.password && item.email === client.email);
|
||||||
|
default: return clients.findIndex(item => item.id === client.id && item.email === client.email);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async addClient(clients, dbInboundId) {
|
async addClient(clients, dbInboundId) {
|
||||||
const data = {
|
const data = {
|
||||||
|
@ -832,8 +837,7 @@
|
||||||
dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
|
dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
|
||||||
inbound = dbInbound.toInbound();
|
inbound = dbInbound.toInbound();
|
||||||
clients = this.getClients(dbInbound.protocol, inbound.settings);
|
clients = this.getClients(dbInbound.protocol, inbound.settings);
|
||||||
client.enable = !client.enable; // For finding correct index in findIndexOfClient() function
|
index = this.findIndexOfClient(dbInbound.protocol, clients, client);
|
||||||
index = this.findIndexOfClient(clients, client);
|
|
||||||
clients[index].enable = !clients[index].enable;
|
clients[index].enable = !clients[index].enable;
|
||||||
clientId = this.getClientId(dbInbound.protocol, clients[index]);
|
clientId = this.getClientId(dbInbound.protocol, clients[index]);
|
||||||
await this.updateClient(clients[index], dbInboundId, clientId);
|
await this.updateClient(clients[index], dbInboundId, clientId);
|
||||||
|
|
Loading…
Reference in a new issue