{
  "name": "ezGPT - Read Local Note",
  "active": false,
  "nodes": [
    {
      "id": "manual",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        260
      ],
      "parameters": {}
    },
    {
      "id": "read",
      "name": "Read Local File",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [
        220,
        260
      ],
      "alwaysOutputData": true,
      "parameters": {
        "operation": "read",
        "fileSelector": "/files/demo-note.txt",
        "options": {
          "dataPropertyName": "document"
        }
      }
    },
    {
      "id": "check-file",
      "name": "Check File",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        440,
        260
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const items = $input.all();\nif (items.length !== 1 || Object.keys(items[0].binary ?? {}).join('|') !== 'document') {\n  throw new Error('one_document_required');\n}\nconst item = items[0];\nif (item.binary.document.fileName !== 'demo-note.txt') throw new Error('demo_note_required');\nconst bytes = await this.helpers.getBinaryDataBuffer(0, 'document');\nconst text = bytes.toString('utf8');\nif (bytes.length < 1 || bytes.length > 4096 || !Buffer.from(text, 'utf8').equals(bytes) || text.includes('\\u0000')) {\n  throw new Error('small_utf8_text_required');\n}\nreturn [{ json: { source_bytes: bytes.length, file_name: 'demo-note.txt' }, binary: item.binary }];"
      }
    },
    {
      "id": "text",
      "name": "Read Text",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1.1,
      "position": [
        660,
        260
      ],
      "parameters": {
        "operation": "text",
        "binaryPropertyName": "document",
        "destinationKey": "note",
        "options": {
          "encoding": "utf8",
          "stripBOM": true,
          "keepSource": "both"
        }
      }
    },
    {
      "id": "check-note",
      "name": "Check Note",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        880,
        260
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const items = $input.all();\nif (items.length !== 1) throw new Error('one_note_required');\nconst item = items[0];\nif (typeof item.json.note !== 'string' || !item.binary?.document || !Number.isInteger(item.json.source_bytes)) {\n  throw new Error('note_and_source_required');\n}\nconst text = item.json.note.replaceAll('\\r\\n', '\\n');\nconst expected = \"Учебный файл n8n.\\nКод: DEMO-001\\nКоличество: 2\\n\";\nif (text !== expected) throw new Error('demo_note_mismatch');\nreturn [{ json: { file_name: item.json.file_name, text, source_bytes: item.json.source_bytes,\n  verified: true, action: false } }];"
      }
    }
  ],
  "connections": {
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Read Local File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Local File": {
      "main": [
        [
          {
            "node": "Check File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check File": {
      "main": [
        [
          {
            "node": "Read Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Text": {
      "main": [
        [
          {
            "node": "Check Note",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}
