{
  "name": "Google Drive Index Sync - Template",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 24
            }
          ]
        }
      },
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "command": "python3",
        "arguments": [
          "{{ $env.REPO_DIR }}/scripts/generate_drive_index.py",
          "--root-id",
          "{{ $env.GOOGLE_DRIVE_ROOT_ID }}",
          "--root-name",
          "{{ $env.GOOGLE_DRIVE_ROOT_NAME }}",
          "--output",
          "{{ $env.REPO_DIR }}/configs/drive_structure.json",
          "--credentials",
          "{{ $env.GOOGLE_APPLICATION_CREDENTIALS }}"
        ],
        "workingDirectory": "{{ $env.REPO_DIR }}"
      },
      "name": "Generate Drive Index",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{ $json.exitCode }}",
              "operation": "equal",
              "value2": 0
            }
          ]
        }
      },
      "name": "Check Success",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "filePath": "{{ $env.REPO_DIR }}/configs/drive_structure.json"
      },
      "name": "Read Manifest",
      "type": "n8n-nodes-base.readBinaryFile",
      "typeVersion": 1,
      "position": [
        850,
        200
      ]
    },
    {
      "parameters": {
        "jsCode": "const manifest = JSON.parse($input.item.json.data);\nreturn {\n  json: {\n    folders: manifest.stats.folders,\n    files: manifest.stats.files,\n    shortcuts: manifest.stats.shortcuts,\n    total: manifest.stats.total_nodes,\n    generated_at: manifest.generated_at,\n    root_name: manifest.root.name\n  }\n};"
      },
      "name": "Extract Stats",
      "type": "n8n-nodes-base.code",
      "typeVersion": 1,
      "position": [
        1050,
        200
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "post",
        "chatId": "{{ $env.NOTIFICATION_CHAT_ID }}",
        "text": "\u2705 *Google Drive Indexado*\n\n\ud83d\udcca *Estat\u00edsticas:*\n\u2022 Pastas: {{ $json.folders }}\n\u2022 Arquivos: {{ $json.files }}\n\u2022 Atalhos: {{ $json.shortcuts }}\n\u2022 Total: {{ $json.total }}\n\n\ud83d\udd50 Gerado em: {{ $json.generated_at }}"
      },
      "name": "Send Success Notification",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [
        1250,
        200
      ],
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "post",
        "chatId": "{{ $env.NOTIFICATION_CHAT_ID }}",
        "text": "\u274c *Erro na Indexa\u00e7\u00e3o*\n\nVerifique os logs para mais detalhes.\n\nExit Code: {{ $json.exitCode }}"
      },
      "name": "Send Error Notification",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [
        850,
        400
      ],
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Generate Drive Index",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Drive Index": {
      "main": [
        [
          {
            "node": "Check Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Success": {
      "main": [
        [
          {
            "node": "Read Manifest",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Error Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Manifest": {
      "main": [
        [
          {
            "node": "Extract Stats",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Stats": {
      "main": [
        [
          {
            "node": "Send Success Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [],
  "triggerCount": 1,
  "updatedAt": "2026-01-14T10:00:00.000Z",
  "versionId": "1"
}