From 88a2992f84cc73e4612b132698c111e297226d3a Mon Sep 17 00:00:00 2001 From: Nordup Date: Tue, 25 Mar 2025 04:18:48 +0400 Subject: [PATCH] suggestions api --- app/scripts/resources/api_settings.gd | 3 +++ app/scripts/ui/search/search_results.gd | 28 +++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/app/scripts/resources/api_settings.gd b/app/scripts/resources/api_settings.gd index 37d0862..87fb497 100644 --- a/app/scripts/resources/api_settings.gd +++ b/app/scripts/resources/api_settings.gd @@ -31,5 +31,8 @@ var search: String : var prompt: String : get: return url + "/api/prompt?query=" +var search_suggestions: String : + get: return url + "/api/search_suggestions" + var send_logs: String : get: return url + "/api/send_logs?url=" diff --git a/app/scripts/ui/search/search_results.gd b/app/scripts/ui/search/search_results.gd index fee33e8..8dacd73 100644 --- a/app/scripts/ui/search/search_results.gd +++ b/app/scripts/ui/search/search_results.gd @@ -5,7 +5,7 @@ extends VBoxContainer @export var result_scene: PackedScene var result_str: String = "{}" - +var suggestions_str: String = "{}" func _ready() -> void: search(gate_events.current_search_query) @@ -17,7 +17,8 @@ func search(query: String) -> void: var gates = JSON.parse_string(result_str) if gates == null or gates.is_empty(): - Debug.logclr("No gates found", Color.YELLOW) + Debug.logclr("No gates found, request suggestions", Color.YELLOW) + suggestions() return for gate in gates: @@ -36,3 +37,26 @@ func search_request(query: String) -> void: var err = await Backend.request(url, callback) if err != HTTPRequest.RESULT_SUCCESS: Debug.logclr("Cannot send request search", Color.RED) + + +func suggestions() -> void: + await suggestions_request() + + var suggs = JSON.parse_string(suggestions_str) + if suggs == null or suggs.is_empty(): + Debug.logclr("No suggestions found", Color.YELLOW) + return + + for sugg in suggs: + Debug.logr(sugg) + + +func suggestions_request() -> void: + var url = api.search_suggestions + var callback = func(_result, code, _headers, body): + if code == 200: + suggestions_str = body.get_string_from_utf8() + else: Debug.logclr("Request search suggestions failed. Code " + str(code), Color.RED) + + var err = await Backend.request(url, callback) + if err != HTTPRequest.RESULT_SUCCESS: Debug.logclr("Cannot send request search suggestions", Color.RED)