Pixel-Composer/scripts/node_http_request/node_http_request.gml

55 lines
1.4 KiB
Plaintext
Raw Normal View History

2024-07-19 05:20:18 +02:00
function Node_HTTP_request(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "HTTP";
setDimension(96, 72);
2024-08-18 06:16:20 +02:00
newInput(0, nodeValue_Text("Address", self, ""));
2024-07-19 05:20:18 +02:00
2024-08-18 06:16:20 +02:00
newInput(1, nodeValue_Enum_Scroll("Type", self, 0, [ "Get", "Post" ]));
2024-07-19 05:20:18 +02:00
2024-08-18 09:13:41 +02:00
newInput(2, nodeValue_Text("Content", self, ""))
2024-07-19 05:20:18 +02:00
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Result", self, VALUE_TYPE.text, ""));
2024-07-19 05:20:18 +02:00
address_domain = "";
static update = function() {
var _addr = getInputData(0);
var _type = getInputData(1);
var _post = getInputData(2);
2024-08-08 06:57:51 +02:00
inputs[2].setVisible(_type == 1, _type == 1);
2024-07-19 05:20:18 +02:00
if(_addr == "") return;
var _addrs = string_split(_addr, "/", true);
address_domain = array_safe_get(_addrs, 1, "");
draw_set_font(f_p0);
address_domain = string_cut_line(address_domain, 128);
switch(_type) {
case 0 :
asyncCall(http_get(_addr), function(param, data) /*=>*/ {
var res = data[? "result"];
2024-08-08 06:57:51 +02:00
outputs[0].setValue(res);
2024-07-19 05:20:18 +02:00
triggerRender(false);
});
break;
case 1 :
asyncCall(http_post_string(_addr, _post), function(param, data) /*=>*/ {
var res = data[? "result"];
2024-08-08 06:57:51 +02:00
outputs[0].setValue(res);
2024-07-19 05:20:18 +02:00
triggerRender(false);
});
break;
}
}
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
var addr = getInputData(0);
var bbox = drawGetBbox(xx, yy, _s);
draw_set_text(f_sdf, fa_center, fa_center, COLORS._main_text);
draw_text_bbox(bbox, address_domain);
}
}