From d955f22e81e5813083cd14fcb8cd40fcadaf5ab6 Mon Sep 17 00:00:00 2001 From: Clemens Tolboom Date: Fri, 30 Jun 2023 12:50:39 +0200 Subject: [PATCH] Make API key entry better. --- addons/gd-openai/connector.gd | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/addons/gd-openai/connector.gd b/addons/gd-openai/connector.gd index fedf998..ed8e63a 100644 --- a/addons/gd-openai/connector.gd +++ b/addons/gd-openai/connector.gd @@ -22,6 +22,14 @@ const SaveResourcePath:StringName = "user://openai/data/" func _init(): request_completed.connect(_http_request_completed) +func check_api_key(): + const user = preload("res://addons/gd-openai/user_data.tscn") + # FIXME: make this a Popup window +# var c = Popup.new() +# c.add_child(user.instantiate()) +# c.popup() + + get_parent().add_child(user.instantiate()) ## Make is possible to switch versioning.[br] ##[br] @@ -48,6 +56,10 @@ func prepare_request(req,resp): # Before requesting we save the request. save_request(req) + # FIXME: this should be a popup window +# if req._api_key == "": +# check_api_key() + return req.build_request(BaseURL) # ===== DRY alert ==== @@ -102,6 +114,8 @@ func _http_request_completed(result: int, response_code: int, headers: PackedStr if response_code >= 400: printt("ERROR", response_code, response["error"]) error_response.emit(response["error"]) + if response_code == 401: + check_api_key() return _resp.from_dict(response)