diff --git a/.vscode/settings.json b/.vscode/settings.json index 55f96d6..b1f7d4a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,6 @@ { "[python]": { - "editor.defaultFormatter": "ms-python.black-formatter" + "editor.defaultFormatter": "mikoz.black-py" }, "python.formatting.provider": "none" } \ No newline at end of file diff --git a/ktvmanager/lib/checker.py b/ktvmanager/lib/checker.py index bbdd29b..02b7301 100644 --- a/ktvmanager/lib/checker.py +++ b/ktvmanager/lib/checker.py @@ -88,6 +88,7 @@ def validate_account() -> Tuple[Response, int]: password = data.get("password") expiry_date = data.get("expiry_date") stream = data.get("stream") + stream_url = data.get("streamURL") if not all([username, password]): return jsonify({"message": "Missing required fields"}), 400 @@ -97,20 +98,46 @@ def validate_account() -> Tuple[Response, int]: result = single_account_check(account_data, stream_urls) if result: - if expiry_date and stream and int(result["data"]["user_info"]["exp_date"]) != expiry_date: + if result["url"] != stream_url: + from ktvmanager.lib.database import update_stream_url + + update_stream_url(result["url"], stream_url) + return ( + jsonify({"message": "Account is valid and updated", "data": result}), + 200, + ) + + if ( + expiry_date + and stream + and int(result["data"]["user_info"]["exp_date"]) != expiry_date + ): from ktvmanager.lib.database import update_expiry_date + update_expiry_date( username, stream, result["data"]["user_info"]["exp_date"] ) - return jsonify({"message": "Account is valid and updated", "data": result}), 200 + return ( + jsonify({"message": "Account is valid and updated", "data": result}), + 200, + ) - if int(result.get("data", {}).get("user_info", {}).get("max_connections")) and data.get("max_connections") and int(result["data"]["user_info"]["max_connections"]) != data.get("max_connections"): + if ( + int(result.get("data", {}).get("user_info", {}).get("max_connections")) + and data.get("max_connections") + and int(result["data"]["user_info"]["max_connections"]) + != data.get("max_connections") + ): from ktvmanager.lib.database import update_max_connections + update_max_connections( username, stream, int(result["data"]["user_info"]["max_connections"]) ) - return jsonify({"message": "Account is valid and updated", "data": result}), 200 - + return ( + jsonify({"message": "Account is valid and updated", "data": result}), + 200, + ) + return jsonify({"message": "Account is valid", "data": result}), 200 else: - return jsonify({"message": "Account is invalid"}), 401 \ No newline at end of file + return jsonify({"message": "Account is invalid"}), 401 diff --git a/ktvmanager/lib/database.py b/ktvmanager/lib/database.py index 0c3e680..d936ae2 100644 --- a/ktvmanager/lib/database.py +++ b/ktvmanager/lib/database.py @@ -167,6 +167,18 @@ def update_max_connections(username: str, stream: str, max_connections: int) -> _execute_query(query, params) +def update_stream_url(new_stream: str, old_stream: str) -> None: + """Updates the stream URL of an account. + + Args: + new_stream: The stream of the account. + old_stream: The new stream URL. + """ + query = "UPDATE userAccounts SET streamURL = %s WHERE streamURL = %s" + params = (new_stream, old_stream) + _execute_query(query, params) + + def delete_account(user_id: int) -> Response: """Deletes an account for a user.