Fixed TG messages quotes. Fixed sync tasks loop.
All checks were successful
Docker hub build / docker (push) Successful in 9m33s

This commit is contained in:
Ultradesu
2025-09-17 16:34:55 +03:00
parent d4042435fe
commit 777af49ebf
2 changed files with 37 additions and 31 deletions

View File

@@ -351,9 +351,22 @@ class XrayServerV2(Server):
logger.debug(f"Inbound config for {inbound.name}: {len(str(inbound_config))} chars") logger.debug(f"Inbound config for {inbound.name}: {len(str(inbound_config))} chars")
# Add inbound using the client's add_inbound method which handles wrapping # Check if inbound already exists
try: existing_inbounds = client.list_inbounds()
inbound_exists = any(ib.get('tag') == inbound.name for ib in existing_inbounds)
if inbound_exists:
# Inbound already exists, update it instead of recreating
logger.info(f"Inbound {inbound.name} already exists, updating it")
# First remove the old one
client.remove_inbound(inbound.name)
# Then add the updated one
result = client.add_inbound(inbound_config) result = client.add_inbound(inbound_config)
else:
# Add new inbound
logger.info(f"Creating new inbound {inbound.name}")
result = client.add_inbound(inbound_config)
logger.info(f"Deploy inbound result: {result}") logger.info(f"Deploy inbound result: {result}")
# Check if command was successful # Check if command was successful
@@ -370,9 +383,6 @@ class XrayServerV2(Server):
else: else:
logger.error(f"Failed to deploy inbound {inbound.name} on server {self.name}. Result: {result}") logger.error(f"Failed to deploy inbound {inbound.name} on server {self.name}. Result: {result}")
return False return False
except Exception as cmd_error:
logger.error(f"Command execution error: {cmd_error}")
return False
except Exception as e: except Exception as e:
logger.error(f"Error deploying inbound {inbound.name} on server {self.name}: {e}") logger.error(f"Error deploying inbound {inbound.name} on server {self.name}: {e}")
@@ -709,13 +719,10 @@ class XrayServerV2(Server):
logger.error(f"Failed to create inbound {inbound.name} with users") logger.error(f"Failed to create inbound {inbound.name} with users")
continue continue
else: else:
# Inbound exists, add user using recreation approach # Inbound exists, skip individual user addition to avoid constant recreation
logger.info(f"Inbound {inbound.name} exists, adding user via recreation") # User will be added during the next full inbound sync
if self.add_user_to_inbound(user, inbound): logger.info(f"Inbound {inbound.name} exists, user {user.username} will be added during next sync")
added_count += 1 added_count += 1
logger.info(f"Successfully added user {user.username} to existing inbound {inbound.name}")
else:
logger.error(f"Failed to add user {user.username} to existing inbound {inbound.name}")
logger.info(f"Added user {user.username} to {added_count} inbounds on server {self.name}") logger.info(f"Added user {user.username} to {added_count} inbounds on server {self.name}")
return added_count > 0 return added_count > 0

View File

@@ -870,10 +870,9 @@ def sync_server_inbounds(self, server_id, auto_sync_users=True):
logger.info(f"Successfully deployed {deployed_count} inbounds on server {server.name}") logger.info(f"Successfully deployed {deployed_count} inbounds on server {server.name}")
# Automatically sync users after inbound deployment if requested # Don't automatically sync users to avoid loops
if auto_sync_users and deployed_count > 0: # Users are already added when deploying inbounds
logger.info(f"Scheduling user sync for server {server.name} after inbound deployment") logger.info(f"Inbound sync completed for server {server.name}, users were already synced during deployment")
sync_server_users.apply_async(args=[server_id], countdown=5) # 5 second delay
return {"inbounds_deployed": deployed_count, "auto_sync_users": auto_sync_users} return {"inbounds_deployed": deployed_count, "auto_sync_users": auto_sync_users}