diff --git a/nodes/common.py b/nodes/common.py index 890997f..49ee9af 100644 --- a/nodes/common.py +++ b/nodes/common.py @@ -8,6 +8,14 @@ import requests import time import json + +COMFY_KEY_ERROR = ( + "Invalid Token Type\n\n" + "The API token you’ve entered is not a ComfyUI token.\n" + "Please use the valid token from your BRIA Account API Keys page:\n" + "https://platform.bria.ai/console/account/api-keys" +) + def postprocess_image(image): result_image = Image.open(io.BytesIO(image)) result_image = result_image.convert("RGB") @@ -148,14 +156,20 @@ def poll_status_until_completed(status_url, api_key, timeout=360, check_interval raise Exception(f"Timeout reached after {timeout} seconds") -def deserialize_and_get_comfy_key(encoded: str): +def deserialize_and_get_comfy_key(encoded: str) -> str: + """ + Decodes a base64-encoded JSON token and returns the ComfyUI API key. + """ try: decoded = base64.b64decode(encoded).decode("utf-8") payload = json.loads(decoded) - if (payload['type'] == "comfy"): - return payload['apiKey'] - else: - raise Exception(f"Invalid token type") + + if payload.get("type") != "comfy": + raise Exception(COMFY_KEY_ERROR) + + return payload.get("apiKey") + except Exception as e: - raise Exception(f"Invalid token") + raise Exception(COMFY_KEY_ERROR) + diff --git a/pyproject.toml b/pyproject.toml index 5e34640..dc1cd58 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui-bria-api" description = "Custom nodes for ComfyUI using BRIA's API." -version = "2.1.6" +version = "2.1.7" license = {file = "LICENSE"} [project.urls]