-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNokoRunner.gd
More file actions
78 lines (68 loc) · 2.66 KB
/
NokoRunner.gd
File metadata and controls
78 lines (68 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Copyright 2025 Nathanne Isip
# This file is part of Noko (https://github.com/nthnn/noko)
# This code is licensed under MIT license (see LICENSE for details)
# Class for retrieving runner status and version from a remote Noko server.
class_name NokoRunner
const NetUtils = preload("./utils/NetUtils.gd")
# Fetches the current version of the Noko runner from the server.
#
# Initiates an HTTP GET request to the "/api/version" endpoint
# and returns the version string if successful.
#
# @param parent (Node): Node to attach the HTTPRequest to.
# @param server (Dictionary): Server configuration with keys:
# - "host" (String): Hostname or URL (e.g., "http://example.com").
# - "port" (int): Port number (e.g., 8080).
# @param use_ssl (bool): If true, uses HTTPS scheme; otherwise HTTP.
# @return (String): Version string on success, or empty string on error.
static func version(
parent: Node,
server: Dictionary,
use_ssl: bool = true
)-> String:
if (!server.has("host") or
!server.has("port")):
push_error("Server host name and port number must be defined")
return ""
var response = await NetUtils.send_get_request(
parent,
server["host"] + ":" + str(server["port"]) + "/api/version",
{"User-Agent": "noko-godot/0.0.1"},
{},
use_ssl
)
if response["result"] == HTTPRequest.RESULT_CANT_CONNECT:
push_error("Failed to fetch runner version")
return ""
return response["body"]["version"]
# Retrieves the current process status identifier of the Noko runner.
#
# Sends an HTTP GET request to the "/api/ps" endpoint
# and returns the status string (e.g., a process ID or state).
#
# @param parent (Node): Node to attach the HTTPRequest to.
# @param server (Dictionary): Server configuration with keys:
# - "host" (String): Hostname or URL (e.g., "http://example.com").
# - "port" (int): Port number (e.g., 8080).
# @param use_ssl (bool): If true, uses HTTPS scheme; otherwise HTTP.
# @return (String): Process status string on success, or empty string on error.
static func process_status(
parent: Node,
server: Dictionary,
use_ssl: bool = true
)-> String:
if (!server.has("host") or
!server.has("port")):
push_error("Server host name and port number must be defined")
return ""
var response = await NetUtils.send_get_request(
parent,
server["host"] + ":" + str(server["port"]) + "/api/ps",
{"User-Agent": "noko-godot/0.0.1"},
{},
use_ssl
)
if response["result"] == HTTPRequest.RESULT_CANT_CONNECT:
push_error("Failed to fetch runner version")
return ""
return response["body"]["version"]