93 lines
3.5 KiB
GDScript
93 lines
3.5 KiB
GDScript
class_name BugbotServerAPI
|
|
extends Resource
|
|
|
|
enum BugbotServerError { OK, THREAD_NULL, THREAD_BUSY, API_RESPONSE_ERROR }
|
|
enum BugbotTagArray { VERSION, HARDWARE, OS, COMPONENT, SEVERITY, MAX }
|
|
|
|
var __bugbot_server_thread : Thread
|
|
|
|
|
|
func _init():
|
|
__bugbot_server_thread = Thread.new()
|
|
|
|
|
|
func _return_list_of_bugs(map_name:String, callback:Callable) -> int:
|
|
return __start_thread_with_callback(__return_list_of_bugs_thread.bind(map_name, callback))
|
|
|
|
func _prepare_form(callback:Callable) -> int:
|
|
return __start_thread_with_callback(__prepare_form_thread.bind(callback))
|
|
|
|
func _send_form_data(data:Dictionary, map_name:String, bug_position:Vector3, bug_normal:Vector3, callback:Callable) -> int:
|
|
return __start_thread_with_callback(__send_form_data_thread.bind(data, map_name, bug_position, bug_normal, callback))
|
|
|
|
|
|
static func _create_new_server_api() -> BugbotServerAPI:
|
|
match ProjectSettings.get_setting("bugbot/reporting/bug_report_platform", -1):
|
|
BugReportPlatform.BUGZILLA: return BugbotServerAPI.new()
|
|
BugReportPlatform.GITEA: return BugbotServerGiteaAPI.new()
|
|
BugReportPlatform.JIRA: return BugbotServerAPI.new()
|
|
return BugbotServerAPI.new()
|
|
|
|
|
|
func __connect_to_server(http_client:HTTPClient, default_server:String) -> int:
|
|
var full_server : String = ProjectSettings.get_setting("bugbot/reporting/gitea/server", default_server)
|
|
var server_and_port : PackedStringArray = full_server.rsplit(":",true,1)
|
|
var server : String = server_and_port[0]
|
|
var port : int = int(server_and_port[1])
|
|
http_client.connect_to_host(server if port > 0 else full_server, port if port > 0 else -1)
|
|
|
|
while http_client.get_status() == HTTPClient.STATUS_CONNECTING or http_client.get_status() == HTTPClient.STATUS_RESOLVING:
|
|
http_client.poll()
|
|
return http_client.get_status()
|
|
|
|
func __get_http_client_chunk_response(http_client:HTTPClient) -> String:
|
|
if http_client.has_response():
|
|
var response_body : PackedByteArray = PackedByteArray()
|
|
while http_client.get_status() == HTTPClient.STATUS_BODY:
|
|
http_client.poll()
|
|
var chunk : PackedByteArray = http_client.read_response_body_chunk()
|
|
if chunk.size() > 0:
|
|
response_body = response_body + chunk
|
|
return response_body.get_string_from_utf8()
|
|
return ""
|
|
|
|
func __start_thread_with_callback(thread_function:Callable) -> int:
|
|
if not __bugbot_server_thread:
|
|
printerr("Server thread is null.")
|
|
return BugbotServerError.THREAD_NULL
|
|
if __bugbot_server_thread.is_started():
|
|
printerr("Server thread is currently busy.")
|
|
return BugbotServerError.THREAD_BUSY;
|
|
__bugbot_server_thread = Thread.new()
|
|
__bugbot_server_thread.start(thread_function)
|
|
return BugbotServerError.OK
|
|
|
|
func __validate_server_response(_response:Variant) -> int:
|
|
return Error.OK
|
|
|
|
|
|
func _current_server_api() -> String:
|
|
return ""
|
|
|
|
func __build_url_string(_api_suffix:String) -> String:
|
|
return ""
|
|
|
|
func __create_header_data(content_length:int = -1) -> Array:
|
|
return []
|
|
|
|
|
|
func __return_list_of_bugs_thread(map_name:String, callback:Callable) -> void:
|
|
print("Insert list of ", _current_server_api(), " bugs here.")
|
|
callback.call_deferred([])
|
|
__bugbot_server_thread.call_deferred("wait_to_finish")
|
|
|
|
func __prepare_form_thread(callback:Callable) -> void:
|
|
print("Prepare ", _current_server_api(), " form here.")
|
|
callback.call_deferred([])
|
|
__bugbot_server_thread.call_deferred("wait_to_finish")
|
|
|
|
func __send_form_data_thread(data:Dictionary, map_name:String, bug_position:Vector3, bug_normal:Vector3, callback:Callable) -> void:
|
|
print("Send ", _current_server_api(), " form data here.")
|
|
callback.call_deferred([])
|
|
__bugbot_server_thread.call_deferred("wait_to_finish")
|