Files
LNXSDK/leenkx/Sources/leenkx/logicnode/CreateTorrentNode.hx
2025-01-22 16:18:30 +01:00

44 lines
1021 B
Haxe

package leenkx.logicnode;
import leenkx.system.Event;
import leenkx.network.Leenkx;
import iron.object.Object;
class CreateTorrentNode extends LogicNode {
public var torrent: Dynamic;
public var net_Url: String;
public function new(tree:LogicTree) {
super(tree);
}
override function run(from:Int) {
var connection = inputs[1].get();
if (connection == null) return;
var data = inputs[2].get();
if (data == null) return;
net_Url = connection._url;
var script = 'var file = ' + data + ';
lx_' + net_Url +'.wt.add(file, function (torrent) {
leenkx.network.Leenkx.file.set("' + net_Url +'", torrent.files);
torrent.on("done", function () {
leenkx.network.Leenkx.connections.h["' + net_Url +'"].ontorrentdone();
});
});
';
js.Syntax.code('(1, eval)({0})', script.toString());
runOutput(0);
}
override function get(from: Int): Dynamic {
return switch (from) {
case 1: Leenkx.file.get(net_Url);
default: throw "Unreachable";
}
}
}