Update network.js

This commit is contained in:
Javi Agenjo
2023-10-26 20:31:10 +02:00
committed by GitHub
parent fbdd6aeab3
commit 2bc9fd9e41

View File

@@ -362,4 +362,61 @@
};
LiteGraph.registerNodeType("network/sillyclient", LGSillyClient);
//HTTP Request
function HTTPRequestNode() {
this.addInput("request", LiteGraph.ACTION);
this.addInput("url", "string");
this.addProperty("url", "string");
this.addOutput("ready", LiteGraph.EVENT);
this.addOutput("data", "string");
this._data = null;
this._fetching = null;
}
HTTPRequestNode.title = "HTTP Request";
HTTPRequestNode.desc = "Fetch data through HTTP";
HTTPRequestNode.prototype.fetch = function()
{
this.boxcolor = "#FF0";
var that = this;
this._fetching = fetch(url)
.then(resp=>{
if(!resp.ok)
{
this.boxcolor = "#F00";
that.trigger("error");
}
else
{
this.boxcolor = "#0F0";
return resp.text();
}
})
.then(data=>{
that._data = data;
that._fetching = null;
that.trigger("ready");
});
}
HTTPRequestNode.prototype.onAction = function(evt)
{
if(evt == "request")
this.fetch();
}
HTTPRequestNode.prototype.onExecute = function() {
this.setOutputData(1, this._data);
};
HTTPRequestNode.prototype.onGetOutputs = function() {
return [["error",LiteGraph.EVENT]];
}
LiteGraph.registerNodeType("network/httprequest", HTTPRequestNode);
})(this);