mirror of
https://github.com/thegatesbrowser/thegates.git
synced 2025-08-18 12:16:33 -04:00
suggestions api
This commit is contained in:
parent
cb70ef59aa
commit
88a2992f84
2 changed files with 29 additions and 2 deletions
|
@ -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="
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue