diff --git a/pyxui/methods/clients.py b/pyxui/methods/clients.py index 472b35c..8078544 100644 --- a/pyxui/methods/clients.py +++ b/pyxui/methods/clients.py @@ -37,12 +37,13 @@ def get_client( continue settings = json.loads(inbound['settings']) - + protocol = inbound['protocol'] for client in settings['clients']: - if client['email'] != email and client['id'] != uuid: + clientid = client['id'] if protocol in ['vless','vmess'] else client['password'] + if client['email'] != email and clientid != uuid: continue - return client + return client , protocol raise errors.NotFound() @@ -186,14 +187,14 @@ def delete_client( `~Dict`: On success, a dict is returned else 404 error will be raised """ - find_client = self.get_client( + find_client , protocol = self.get_client( inbound_id=inbound_id, email=email, uuid=uuid ) - + clientid = find_client['id'] if protocol in ['vless','vmess'] else find_client['password'] response = self.request( - path=f"{inbound_id}/delClient/{find_client['id']}", + path=f"{inbound_id}/delClient/{clientid}", method="POST" ) @@ -249,16 +250,16 @@ def update_client( `~Dict`: On success, a dict is returned else 404 error will be raised """ - find_client = self.get_client( + find_client , protocol = self.get_client( inbound_id=inbound_id, email=email, uuid=uuid ) - + uuid_key = "password" if protocol == 'trojan' else "id" settings = { "clients": [ { - "id": uuid, + uuid_key: uuid, "email": email, "enable": enable, "flow": flow, @@ -272,14 +273,14 @@ def update_client( "decryption": "none", "fallbacks": [] } - + params = { "id": inbound_id, "settings": json.dumps(settings) } - + clientid = find_client['id'] if protocol in ['vless','vmess'] else find_client['password'] response = self.request( - path=f"updateClient/{find_client['id']}", + path=f"updateClient/{clientid}", method="POST", params=params )