{
  "name": "Google Drive \u2192 DocBrain Import",
  "nodes": [
    {
      "parameters": {},
      "id": "a1b2c3d4-0001-0001-0001-000000000001",
      "name": "Start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 */6 * * *"
            }
          ]
        }
      },
      "id": "a1b2c3d4-0001-0001-0001-000000000002",
      "name": "Every 6 hours",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        240,
        480
      ]
    },
    {
      "parameters": {
        "operation": "filesList",
        "folderId": {
          "__rl": true,
          "value": "={{ $vars.GDRIVE_FOLDER_ID }}",
          "mode": "id"
        },
        "options": {
          "fields": "id,name,mimeType,modifiedTime"
        }
      },
      "id": "a1b2c3d4-0001-0001-0001-000000000003",
      "name": "List Drive Files",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        460,
        390
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "notes": "\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u0442\u0435: Credentials \u2192 Google Drive (DocBrain) OAuth2.\n\u041f\u0430\u043f\u043a\u0430 Google Drive \u0437\u0430\u0434\u0430\u0451\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 Variables: GDRIVE_FOLDER_ID."
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "combinator": "or"
          },
          "conditions": [
            {
              "leftValue": "={{ $json.mimeType }}",
              "rightValue": "application/pdf",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            },
            {
              "leftValue": "={{ $json.mimeType }}",
              "rightValue": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            },
            {
              "leftValue": "={{ $json.mimeType }}",
              "rightValue": "text/plain",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            },
            {
              "leftValue": "={{ $json.mimeType }}",
              "rightValue": "text/markdown",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            },
            {
              "leftValue": "={{ $json.mimeType }}",
              "rightValue": "application/vnd.google-apps.document",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ]
        }
      },
      "id": "a1b2c3d4-0001-0001-0001-000000000004",
      "name": "Filter supported types",
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2,
      "position": [
        680,
        390
      ]
    },
    {
      "parameters": {
        "operation": "download",
        "fileId": {
          "__rl": true,
          "value": "={{ $json.id }}",
          "mode": "id"
        },
        "options": {
          "googleFileConversion": {
            "conversion": {
              "docsToFormat": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
            }
          }
        }
      },
      "id": "a1b2c3d4-0001-0001-0001-000000000005",
      "name": "Download File",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        900,
        390
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://docbrain-backend:8000/api/import/gdrive",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-API-Key",
              "value": "={{ $env.DOCBRAIN_API_KEY }}"
            }
          ]
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "name": "file_id",
              "value": "={{ $('Filter supported types').item.json.id }}"
            },
            {
              "parameterType": "formBinaryData",
              "name": "file",
              "inputDataFieldName": "data"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "neverError": false
            }
          }
        }
      },
      "id": "a1b2c3d4-0001-0001-0001-000000000006",
      "name": "POST to DocBrain",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1120,
        390
      ],
      "onError": "continueRegularOutput",
      "notes": "X-API-Key \u0431\u0435\u0440\u0451\u0442\u0441\u044f \u0438\u0437 env-\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 DOCBRAIN_API_KEY \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 n8n.\n\u041f\u0440\u0438 \u043e\u0448\u0438\u0431\u043a\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u2014 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445."
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "List Drive Files",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Every 6 hours": {
      "main": [
        [
          {
            "node": "List Drive Files",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List Drive Files": {
      "main": [
        [
          {
            "node": "Filter supported types",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter supported types": {
      "main": [
        [
          {
            "node": "Download File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download File": {
      "main": [
        [
          {
            "node": "POST to DocBrain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    "docbrain",
    "gdrive"
  ],
  "triggerCount": 1,
  "versionId": "1"
}