{
  "name": "MetaGhost 1.0.81 - Local API starter",
  "nodes": [
    {
      "id": "start",
      "name": "Start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "parameters": {},
      "position": [
        0,
        0
      ]
    },
    {
      "id": "configure",
      "name": "Configure",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "baseUrl",
              "name": "baseUrl",
              "value": "http://127.0.0.1:3847/api",
              "type": "string"
            },
            {
              "id": "filePath",
              "name": "filePath",
              "value": "C:\\Media\\photo.jpg",
              "type": "string"
            },
            {
              "id": "outputFolder",
              "name": "outputFolder",
              "value": "C:\\Media\\output",
              "type": "string"
            },
            {
              "id": "startedAt",
              "name": "startedAt",
              "value": "={{ Date.now() }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "position": [
        240,
        0
      ]
    },
    {
      "id": "check-api",
      "name": "Check API",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "parameters": {
        "url": "={{ $('Configure').first().json.baseUrl + '/health' }}",
        "options": {
          "timeout": 30000,
          "redirect": {
            "redirect": {
              "followRedirects": false
            }
          },
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        }
      },
      "position": [
        480,
        0
      ]
    },
    {
      "id": "desktop-1.0.81-available",
      "name": "Desktop 1.0.81 available",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "check",
              "leftValue": "={{ $json.status === \"ok\" && $json.version === \"1.0.81\" }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "position": [
        720,
        0
      ]
    },
    {
      "id": "submit-job",
      "name": "Submit job",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "parameters": {
        "url": "={{ $('Configure').first().json.baseUrl + '/jobs' }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "timeout": 30000,
          "redirect": {
            "redirect": {
              "followRedirects": false
            }
          },
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        },
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ filePath: $('Configure').first().json.filePath, outputFolder: $('Configure').first().json.outputFolder, batchCount: 1 }) }}"
      },
      "position": [
        960,
        -120
      ],
      "retryOnFail": false,
      "notes": "Select Header Auth: Authorization = Bearer YOUR_KEY. No automatic POST retry. Inspect the accepted job before a new execution."
    },
    {
      "id": "wait",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "parameters": {
        "resume": "timeInterval",
        "amount": 2,
        "unit": "seconds"
      },
      "position": [
        1200,
        -120
      ],
      "webhookId": "metaghost-local-api-poll"
    },
    {
      "id": "read-job",
      "name": "Read job",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "parameters": {
        "url": "={{ $('Configure').first().json.baseUrl + '/jobs/' + encodeURIComponent($('Submit job').first().json.jobId) }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "timeout": 30000,
          "redirect": {
            "redirect": {
              "followRedirects": false
            }
          },
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        }
      },
      "position": [
        1440,
        -120
      ]
    },
    {
      "id": "finished",
      "name": "Finished",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "check",
              "leftValue": "={{ [\"completed\", \"failed\", \"cancelled\"].includes($json.status) }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "position": [
        1680,
        -120
      ]
    },
    {
      "id": "complete-result",
      "name": "Complete result",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "check",
              "leftValue": "={{ $json.status === \"completed\" && !($json.errors || []).length && !($(\"Submit job\").first().json.skipped || []).length }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "position": [
        1920,
        -240
      ]
    },
    {
      "id": "within-deadline",
      "name": "Within deadline",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "check",
              "leftValue": "={{ Date.now() - $('Configure').first().json.startedAt < 600000 }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "position": [
        1920,
        100
      ]
    },
    {
      "id": "download-output",
      "name": "Download output",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "parameters": {
        "url": "={{ $('Configure').first().json.baseUrl + '/download/' + encodeURIComponent($('Submit job').first().json.jobId) + '?index=0' }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "timeout": 120000,
          "redirect": {
            "redirect": {
              "followRedirects": false
            }
          },
          "response": {
            "response": {
              "responseFormat": "file",
              "outputPropertyName": "data"
            }
          }
        }
      },
      "position": [
        2160,
        -360
      ]
    },
    {
      "id": "inspect-failure",
      "name": "Inspect failure",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "parameters": {
        "errorMessage": "={{ \"Job \" + $(\"Submit job\").first().json.jobId + \" did not finish successfully. Inspect errors, skipped and results in Read job. Do not resubmit blindly.\" }}"
      },
      "position": [
        2160,
        -100
      ]
    },
    {
      "id": "wait-timed-out",
      "name": "Wait timed out",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "parameters": {
        "errorMessage": "={{ \"Stopped waiting for \" + $(\"Submit job\").first().json.jobId + \". The Desktop job was NOT cancelled. Inspect it before retrying.\" }}"
      },
      "position": [
        2160,
        180
      ]
    },
    {
      "id": "check-desktop-version",
      "name": "Check Desktop version",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "parameters": {
        "errorMessage": "This workflow targets Desktop 1.0.81. Check /api/health and the guide for your installed version."
      },
      "position": [
        960,
        180
      ]
    },
    {
      "id": "read-me",
      "name": "Read me",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "parameters": {
        "content": "## MetaGhost Desktop 1.0.81\n1. Run n8n directly on the Desktop computer.\n2. Enable Settings > API and Apply changes.\n3. Edit Configure local paths.\n4. Create Header Auth: Authorization = Bearer YOUR_KEY. Select it on Submit job, Read job, Download output.\n5. Execute manually with a small file. Output is binary field data.\n\nEach POST creates a new job. Never retry automatically. A timeout does not cancel the job. Check GET /api/jobs before a new execution.\n\nhttps://metaghost.io/docs/api#n8n",
        "height": 420,
        "width": 520
      },
      "position": [
        0,
        -480
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Configure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Configure": {
      "main": [
        [
          {
            "node": "Check API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check API": {
      "main": [
        [
          {
            "node": "Desktop 1.0.81 available",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Desktop 1.0.81 available": {
      "main": [
        [
          {
            "node": "Submit job",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Check Desktop version",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Submit job": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Read job",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read job": {
      "main": [
        [
          {
            "node": "Finished",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Finished": {
      "main": [
        [
          {
            "node": "Complete result",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Within deadline",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Complete result": {
      "main": [
        [
          {
            "node": "Download output",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Inspect failure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Within deadline": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait timed out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "executionTimeout": 900,
    "saveManualExecutions": true
  },
  "pinData": {},
  "tags": []
}
