From 35d917b88743c783e7ff373df4e04a0b102c56c1 Mon Sep 17 00:00:00 2001 From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com> Date: Mon, 14 Apr 2025 12:53:15 +0330 Subject: [PATCH] feat : Optimize user edit workflow and eliminate service restart delay --- core/cli.py | 2 ++ core/scripts/hysteria2/edit_user.sh | 2 +- core/scripts/webpanel/routers/api/v1/user.py | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/cli.py b/core/cli.py index b8e7c03..8b720ba 100644 --- a/core/cli.py +++ b/core/cli.py @@ -148,6 +148,8 @@ def add_user(username: str, traffic_limit: int, expiration_days: int, password: @click.option('--blocked', '-b', is_flag=True, help='Block the user') def edit_user(username: str, new_username: str, new_traffic_limit: int, new_expiration_days: int, renew_password: bool, renew_creation_date: bool, blocked: bool): try: + cli_api.kick_user_by_name(username) + cli_api.traffic_status(display_output=False) cli_api.edit_user(username, new_username, new_traffic_limit, new_expiration_days, renew_password, renew_creation_date, blocked) click.echo(f"User '{username}' updated successfully.") diff --git a/core/scripts/hysteria2/edit_user.sh b/core/scripts/hysteria2/edit_user.sh index 5deee56..d409d3d 100644 --- a/core/scripts/hysteria2/edit_user.sh +++ b/core/scripts/hysteria2/edit_user.sh @@ -224,7 +224,7 @@ edit_user() { new_creation_date=${new_creation_date:-$creation_date} new_blocked=$(convert_blocked_status "${new_blocked:-$blocked}") - python3 $CLI_PATH restart-hysteria2 +# python3 $CLI_PATH restart-hysteria2 if ! update_user_info "$username" "$new_username" "$new_password" "$new_traffic_limit" "$new_expiration_days" "$new_creation_date" "$new_blocked"; then return 1 # Update user failed diff --git a/core/scripts/webpanel/routers/api/v1/user.py b/core/scripts/webpanel/routers/api/v1/user.py index 828ceb3..a826bfd 100644 --- a/core/scripts/webpanel/routers/api/v1/user.py +++ b/core/scripts/webpanel/routers/api/v1/user.py @@ -85,6 +85,8 @@ async def edit_user_api(username: str, body: EditUserInputBody): HTTPException: if an error occurs while editing the user. """ try: + cli_api.kick_user_by_name(username) + cli_api.traffic_status(display_output=False) cli_api.edit_user(username, body.new_username, body.new_traffic_limit, body.new_expiration_days, body.renew_password, body.renew_creation_date, body.blocked) return DetailResponse(detail=f'User {username} has been edited.')