{
	"id": "0a31871f47eb0214",
	"type": "subflow",
	"name": "OSCAR Fish Detector ZIP Async",
	"info": "",
	"category": "OSCAR",
	"in": [
		{
			"x": 120,
			"y": 160,
			"wires": [
				{
					"id": "092c4db69d3ec653"
				}
			]
		}
	],
	"out": [
		{
			"x": 1390,
			"y": 380,
			"wires": [
				{
					"id": "f2d95981ddc6710c",
					"port": 0
				}
			]
		},
		{
			"x": 940,
			"y": 420,
			"wires": [
				{
					"id": "c66cc09de4d51bac",
					"port": 0
				}
			]
		}
	],
	"env": [
		{
			"name": "Fish Detector ZIP",
			"type": "str",
			"value": "",
			"ui": {
				"type": "none"
			}
		},
		{
			"name": "MinIOConf",
			"type": "minio-config",
			"value": "",
			"ui": {
				"type": "conf-types"
			}
		},
		{
			"name": "inputBucket",
			"type": "str",
			"value": "",
			"ui": {
				"type": "input",
				"opts": {
					"types": [
						"str"
					]
				}
			}
		},
		{
			"name": "objectName",
			"type": "str",
			"value": "",
			"ui": {
				"type": "input",
				"opts": {
					"types": [
						"str"
					]
				}
			}
		},
		{
			"name": "outputBucket",
			"type": "str",
			"value": "",
			"ui": {
				"type": "input",
				"opts": {
					"types": [
						"str"
					]
				}
			}
		},
		{
			"name": "Prefix",
			"type": "str",
			"value": "",
			"ui": {
				"type": "input",
				"opts": {
					"types": [
						"str"
					]
				}
			}
		}
	],
	"meta": {
		"module": "node-red-contrib-oscar-fishdetector-zip-async",
		"type": "",
		"version": "0.1.2",
		"author": "vicente.rdguezb@gmail.com",
		"desc": "OSCAR Fish Detector ZIP Async",
		"keywords": "Node-RED",
		"license": "Apache-2.0"
	},
	"color": "#3FADB5",
	"outputLabels": [
		"JSON",
		"Image (ubication)"
	],
	"icon": "font-awesome/fa-file-zip-o",
	"status": {
		"x": 1340,
		"y": 60,
		"wires": [
			{
				"id": "bc4c38d653d165be",
				"port": 0
			},
			{
				"id": "b7d738d7e4678fc8",
				"port": 0
			},
			{
				"id": "755247a4b420b4a3",
				"port": 0
			}
		]
	},
	"flow": [
		{
			"id": "092c4db69d3ec653",
			"type": "change",
			"z": "0a31871f47eb0214",
			"name": "",
			"rules": [
				{
					"t": "set",
					"p": "prefixZip",
					"pt": "msg",
					"to": "Prefix",
					"tot": "env"
				},
				{
					"t": "set",
					"p": "outBucket",
					"pt": "msg",
					"to": "outputBucket",
					"tot": "env"
				},
				{
					"t": "set",
					"p": "zip",
					"pt": "msg",
					"to": "payload",
					"tot": "msg"
				},
				{
					"t": "set",
					"p": "inBucket",
					"pt": "msg",
					"to": "inputBucket",
					"tot": "env"
				},
				{
					"t": "set",
					"p": "objectName",
					"pt": "msg",
					"to": "objectName",
					"tot": "env"
				}
			],
			"action": "",
			"property": "",
			"from": "",
			"to": "",
			"reg": false,
			"x": 440,
			"y": 160,
			"wires": [
				[
					"caf3e7c24691732b",
					"842d73fcf56d7323",
					"bc4c38d653d165be"
				]
			]
		},
		{
			"id": "c8daf05933e705fa",
			"type": "zip",
			"z": "0a31871f47eb0214",
			"name": "",
			"mode": "decompress",
			"filename": "",
			"compressionlevel": 6,
			"outasstring": false,
			"x": 890,
			"y": 120,
			"wires": [
				[
					"dfb1a3e4fba2be70"
				]
			]
		},
		{
			"id": "dfb1a3e4fba2be70",
			"type": "function",
			"z": "0a31871f47eb0214",
			"name": "function 39",
			"func": "var data = msg.payload.length\nflow.set(\"total\",data)\nreturn msg;\n",
			"outputs": 1,
			"timeout": "",
			"noerr": 0,
			"initialize": "// Code added here will be run once\n// whenever the node is started.\nflow.set(\"total\", 0)",
			"finalize": "",
			"libs": [],
			"x": 1060,
			"y": 120,
			"wires": [
				[]
			]
		},
		{
			"id": "caf3e7c24691732b",
			"type": "function",
			"z": "0a31871f47eb0214",
			"name": "function 40",
			"func": "msg.stream = msg.zip\nmsg.objectName = msg.objectName\nmsg.bucketName = msg.inBucket\n\nflow.set(\"outBucket_ZIP\", msg.outBucket);\nflow.set(\"prefix_ZIP\", msg.prefixZIP); \n\n\nlet archive_images = flow.get(\"myImageZIP\");\nlet archive_json = flow.get(\"myJsonZIP\");\n\n// Verificar si es un array, si no lo es, inicializarlo\nif (!Array.isArray(archive_images)) {\n    archive_images = [{  image: null }]; // Primera entrada\n} \nif (!Array.isArray(archive_json)) {\n    archive_json = [{  name:null, json:null}]; // Primera entrada\n} \n// Guardar el array actualizado en el contexto de flujo\nflow.set(\"myImageZIP\", archive_images);\nflow.set(\"myJsonZIP\", archive_json);\nreturn msg;",
			"outputs": 1,
			"noerr": 0,
			"initialize": "// Code added here will be run once\n// whenever the node is started.\n flow.set(\"myImageZIP\",\"[]\");\n flow.set(\"myJsonZIP\",\"[]\");\n flow.set(\"json\",\"\")",
			"finalize": "",
			"libs": [],
			"x": 700,
			"y": 160,
			"wires": [
				[
					"582023ef6d62d7d9"
				]
			]
		},
		{
			"id": "842d73fcf56d7323",
			"type": "function",
			"z": "0a31871f47eb0214",
			"name": "function 41",
			"func": "msg.payload = msg.zip\nreturn msg",
			"outputs": 1,
			"noerr": 0,
			"initialize": "// Code added here will be run once\n",
			"finalize": "",
			"libs": [],
			"x": 720,
			"y": 120,
			"wires": [
				[
					"c8daf05933e705fa"
				]
			]
		},
		{
			"id": "582023ef6d62d7d9",
			"type": "objects",
			"z": "0a31871f47eb0214",
			"objects_name": "",
			"host": "${MinIOConf}",
			"objects_operation": "putObject",
			"objects_bucket": "",
			"objects_object": "",
			"objects_offset": "",
			"objects_length": "",
			"objects_stream": "",
			"objects_size": "",
			"objects_metadata": "",
			"objects_sourceobject": "",
			"objects_conditions": "",
			"objects_objectslist": [],
			"objects_prefix": "",
			"objects_etag": "",
			"objects_datetime": "",
			"x": 900,
			"y": 160,
			"wires": [
				[
					"3f2acb51d86c0b36"
				],
				[]
			]
		},
		{
			"id": "e1d33086dc18832d",
			"type": "notifications",
			"z": "0a31871f47eb0214",
			"notifications_name": "",
			"host": "${MinIOConf}",
			"notifications_operation": "listenBucketNotification",
			"notifications_bucket": "",
			"notifications_notificationconfig": "",
			"notifications_prefix": "",
			"notifications_suffix": "",
			"notifications_events": "",
			"notifications_events_object_created_put": true,
			"notifications_events_object_created_post": false,
			"notifications_events_object_created_copy": false,
			"notifications_events_object_created_complete_multipart_upload": false,
			"notifications_events_object_removed_delete": false,
			"notifications_events_object_accessed_get": false,
			"notifications_events_object_accessed_head": false,
			"x": 360,
			"y": 240,
			"wires": [
				[
					"57262339a87b9a03"
				],
				[]
			]
		},
		{
			"id": "57262339a87b9a03",
			"type": "delay",
			"z": "0a31871f47eb0214",
			"name": "",
			"pauseType": "rate",
			"timeout": "4",
			"timeoutUnits": "seconds",
			"rate": "1",
			"nbRateUnits": "5",
			"rateUnits": "second",
			"randomFirst": "1",
			"randomLast": "5",
			"randomUnits": "seconds",
			"drop": false,
			"allowrate": false,
			"outputs": 1,
			"x": 300,
			"y": 360,
			"wires": [
				[
					"5bfae418a9731def"
				]
			]
		},
		{
			"id": "8c622781198ca383",
			"type": "delay",
			"z": "0a31871f47eb0214",
			"name": "",
			"pauseType": "rate",
			"timeout": "4",
			"timeoutUnits": "seconds",
			"rate": "1",
			"nbRateUnits": "4",
			"rateUnits": "second",
			"randomFirst": "1",
			"randomLast": "5",
			"randomUnits": "seconds",
			"drop": false,
			"allowrate": false,
			"outputs": 1,
			"x": 640,
			"y": 300,
			"wires": [
				[
					"cc35c49fdb3fd7eb"
				]
			]
		},
		{
			"id": "5bfae418a9731def",
			"type": "function",
			"z": "0a31871f47eb0214",
			"name": "function 42",
			"func": "var text = msg.payload.listenBucketNotification.s3.object.key;\n\nvar out = flow.get(\"outBucket_ZIP\")\nmsg.objectName = text\nmsg.bucketName = out\n\nvar n_jpeg = flow.get(\"n_jpeg\")\nlet archive_images = flow.get(\"myImageZIP\") || [];\n\n\nif (msg.objectName.endsWith('.json')) {\n    // Acción para archivos .json\n    \n    \n    flow.set(\"json\", text)\n  \n    \n    return [msg, null]; \n     // Devuelve a la primera salida\n}\n// Comprobar si el archivo termina en .jpg\nelse {\n    flow.set(\"nameImage\",text)\n    archive_images[n_jpeg] = text ;\n    flow.set(\"n_jpeg\", n_jpeg + 1)\n    flow.set(\"myImageZIP\", archive_images);\n    \n    return [null, msg];  // Ninguna salida se activa\n}",
			"outputs": 2,
			"noerr": 0,
			"initialize": "// Code added here will be run once\n// whenever the node is started.\nflow.set(\"n_json\",0)\nflow.set(\"n_jpeg\",0)",
			"finalize": "",
			"libs": [],
			"x": 490,
			"y": 360,
			"wires": [
				[
					"8c622781198ca383"
				],
				[
					"c66cc09de4d51bac"
				]
			]
		},
		{
			"id": "c66cc09de4d51bac",
			"type": "function",
			"z": "0a31871f47eb0214",
			"name": "function 43",
			"func": "var data = msg.payload\nvar total=flow.get(\"total\")\n\n\n\nlet archive_image= flow.get(\"myImageZIP\") || [];\n\nif (archive_image.length==total){\nmsg.payload=archive_image\nmsg.end=\"ready\"\nreturn msg;\n}\n",
			"outputs": 1,
			"timeout": "",
			"noerr": 0,
			"initialize": "// Code added here will be run once\n// whenever the node is started.\nflow.set(\"i\", 0)",
			"finalize": "",
			"libs": [],
			"x": 670,
			"y": 400,
			"wires": [
				[]
			]
		},
		{
			"id": "f28502a40c25ea97",
			"type": "function",
			"z": "0a31871f47eb0214",
			"name": "function 45",
			"func": "msg.payload = msg.payload.objectData\n\n\n\nreturn msg;",
			"outputs": 1,
			"noerr": 0,
			"initialize": "",
			"finalize": "",
			"libs": [],
			"x": 1030,
			"y": 300,
			"wires": [
				[
					"3c0f02d6cf128408"
				]
			]
		},
		{
			"id": "3c0f02d6cf128408",
			"type": "json",
			"z": "0a31871f47eb0214",
			"name": "",
			"property": "payload",
			"action": "",
			"pretty": true,
			"x": 1170,
			"y": 300,
			"wires": [
				[
					"f2d95981ddc6710c"
				]
			]
		},
		{
			"id": "cc35c49fdb3fd7eb",
			"type": "objects",
			"z": "0a31871f47eb0214",
			"objects_name": "",
			"host": "${MinIOConf}",
			"objects_operation": "getObject",
			"objects_bucket": "",
			"objects_object": "",
			"objects_offset": "",
			"objects_length": "",
			"objects_stream": "",
			"objects_size": "",
			"objects_metadata": "",
			"objects_sourceobject": "",
			"objects_conditions": "",
			"objects_objectslist": [],
			"objects_prefix": "",
			"objects_etag": "",
			"objects_datetime": "",
			"x": 830,
			"y": 300,
			"wires": [
				[
					"f28502a40c25ea97"
				],
				[]
			]
		},
		{
			"id": "f2d95981ddc6710c",
			"type": "function",
			"z": "0a31871f47eb0214",
			"name": "function 46",
			"func": "var data = msg.payload\nvar total = flow.get(\"total\")\nlet archive_json = flow.get(\"myJsonZIP\") || [];\nvar n_json= flow.get(\"n_json\")\nvar name =flow.get(\"json\")\nlet msg1=\"\"\n\n\narchive_json[n_json] = {  name: name,json:data };\n\nflow.set(\"n_json\", n_json + 1)\nflow.set(\"myJsonZIP\", archive_json);\n\n\nif (archive_json.length ==total){\nmsg.payload=archive_json\n\n\nreturn msg}\n",
			"outputs": 1,
			"timeout": "",
			"noerr": 0,
			"initialize": "",
			"finalize": "",
			"libs": [],
			"x": 1230,
			"y": 360,
			"wires": [
				[
					"b7d738d7e4678fc8"
				]
			]
		},
		{
			"id": "3f2acb51d86c0b36",
			"type": "function",
			"z": "0a31871f47eb0214",
			"name": "function 47",
			"func": "var out=flow.get(\"outBucket_ZIP\")\nvar prefix = flow.get(\"prefix_ZIP\")\nmsg.prefix =prefix\nmsg.bucketName=out\nreturn msg;",
			"outputs": 1,
			"noerr": 0,
			"initialize": "",
			"finalize": "",
			"libs": [],
			"x": 120,
			"y": 240,
			"wires": [
				[
					"e1d33086dc18832d"
				]
			]
		},
		{
			"id": "b25bb09360ccd7cd",
			"type": "catch",
			"z": "0a31871f47eb0214",
			"name": "",
			"scope": null,
			"uncaught": false,
			"x": 990,
			"y": 80,
			"wires": [
				[
					"755247a4b420b4a3"
				]
			]
		},
		{
			"id": "bc4c38d653d165be",
			"type": "change",
			"z": "0a31871f47eb0214",
			"name": "Start Service",
			"rules": [
				{
					"t": "delete",
					"p": "payload",
					"pt": "msg"
				},
				{
					"t": "set",
					"p": "payload.text",
					"pt": "msg",
					"to": "Processing....",
					"tot": "str"
				},
				{
					"t": "set",
					"p": "payload.shape",
					"pt": "msg",
					"to": "dot",
					"tot": "str"
				},
				{
					"t": "set",
					"p": "payload.fill",
					"pt": "msg",
					"to": "green",
					"tot": "str"
				}
			],
			"action": "",
			"property": "",
			"from": "",
			"to": "",
			"reg": false,
			"x": 870,
			"y": 20,
			"wires": [
				[]
			]
		},
		{
			"id": "755247a4b420b4a3",
			"type": "change",
			"z": "0a31871f47eb0214",
			"name": "Error Service",
			"rules": [
				{
					"t": "delete",
					"p": "payload",
					"pt": "msg"
				},
				{
					"t": "set",
					"p": "payload.text",
					"pt": "msg",
					"to": "error.message",
					"tot": "msg"
				},
				{
					"t": "set",
					"p": "payload.shape",
					"pt": "msg",
					"to": "dot",
					"tot": "str"
				},
				{
					"t": "set",
					"p": "payload.fill",
					"pt": "msg",
					"to": "red",
					"tot": "str"
				}
			],
			"action": "",
			"property": "",
			"from": "",
			"to": "",
			"reg": false,
			"x": 1150,
			"y": 80,
			"wires": [
				[]
			]
		},
		{
			"id": "b7d738d7e4678fc8",
			"type": "change",
			"z": "0a31871f47eb0214",
			"name": "End Service",
			"rules": [
				{
					"t": "delete",
					"p": "payload",
					"pt": "msg"
				},
				{
					"t": "set",
					"p": "payload.text",
					"pt": "msg",
					"to": "Finished!",
					"tot": "str"
				},
				{
					"t": "set",
					"p": "payload.shape",
					"pt": "msg",
					"to": "dot",
					"tot": "str"
				},
				{
					"t": "set",
					"p": "payload.fill",
					"pt": "msg",
					"to": "blue",
					"tot": "str"
				}
			],
			"action": "",
			"property": "",
			"from": "",
			"to": "",
			"reg": false,
			"x": 1290,
			"y": 200,
			"wires": [
				[]
			]
		},
		{
			"id": "4c08f6965930c005",
			"type": "subflow:0a31871f47eb0214",
			"z": "8c95e5dd22c4eae1",
			"name": "",
			"env": [
				{
					"name": "MinIOConf",
					"value": "cbb2f48dd9e9b3fa",
					"type": "conf-type"
				}
			],
			"x": 690,
			"y": 360,
			"wires": [
				[
					"5337f0c290cac0f6"
				],
				[
					"5bfdb85ff692a1c8",
					"d8c55e7e18bce81d"
				]
			]
		}
	]
}
