{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "3a204dbb-8945-4fd1-8d09-9980a664128f",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -1024,
        -848
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "1d9e1318-89b1-436f-abf1-0ea269f35644",
      "name": "Create folder",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -768,
        -848
      ],
      "parameters": {
        "name": "=< Folder Name >",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "resource": "folder"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "f44f1434-e002-4478-bbd5-498dff5a8e40",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -64,
        -848
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "af7d12c5-fd15-4ed3-8bf4-11901dc21f89",
      "name": "Upload to Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "onError": "continueRegularOutput",
      "position": [
        832,
        -848
      ],
      "parameters": {
        "name": "={{ 'Upscaled_Picture' + $now.format('yyyy-MM-dd_HH-mm-ss') + '.png' }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.gdriveUploadFolderId }}"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "6bab8092-e2a1-4640-acf5-07e4e15d656f",
      "name": "Download Upscale",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueRegularOutput",
      "position": [
        384,
        -928
      ],
      "parameters": {
        "url": "={{ $json.output }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "444a3467-8416-4dfd-ad89-1be387ea4613",
      "name": "Extract Portrait URLS from Airtable Output",
      "type": "n8n-nodes-base.code",
      "position": [
        -288,
        -848
      ],
      "parameters": {
        "jsCode": "// N8N Code Node - Extract Portrait Photo URLs from Airtable Output\n\n// Input data from Airtable\nconst airtableData = $input.all()[0].json;\n\n// Get Google Drive folder ID from previous node\nconst folderId = $node[\"Create folder\"].json.id;\n\n// Extract URLs from PortraitFotoAuswahl array\nconst portraitUrls = [];\n\nif (airtableData.PortraitFotoAuswahl && Array.isArray(airtableData.PortraitFotoAuswahl)) {\n airtableData.PortraitFotoAuswahl.forEach((item, index) => {\n   if (item.url) {\n     portraitUrls.push({\n       index: index,\n       url: item.url,\n       filename: item.filename || `portrait_${index}`,\n       size: item.size || null,\n       width: item.width || null,\n       height: item.height || null,\n       gdriveUploadFolderId: folderId\n     });\n   }\n });\n}\n\n// Return array of URLs with folder ID\nreturn portraitUrls.map(item => ({\n json: {\n   url: item.url,\n   index: item.index,\n   filename: item.filename,\n   size: item.size,\n   width: item.width,\n   height: item.height,\n   gdriveUploadFolderId: item.gdriveUploadFolderId\n }\n}));"
      },
      "typeVersion": 2
    },
    {
      "id": "5868126e-c299-4574-9170-ce02655a59ad",
      "name": "Replicate Upscaler",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        160,
        -928
      ],
      "parameters": {
        "url": "https://api.replicate.com/v1/predictions",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"version\": \"nightmareai/real-esrgan:f121d640bd286e1fdc67f9799164c1d5be36ff74576ee11c803ae5b665dd46aa\",\n  \"input\": {\n    \"image\": \"{{ $json.url }}\",\n    \"scale\": 2,\n    \"face_enhance\": false\n  }\n} ",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Prefer",
              "value": "wait"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "94532da7-1ca5-4d71-b906-677964f0490f",
      "name": "Set GDrive Upload Folder ID",
      "type": "n8n-nodes-base.code",
      "position": [
        608,
        -928
      ],
      "parameters": {
        "jsCode": "// Set Node JavaScript Code\nconst currentItem = $input.all()[0];\nconst loopData = $node[\"Loop Over Items\"].json;\n\nreturn [{\n  json: {\n    gdriveUploadFolderId: loopData.gdriveUploadFolderId,\n    originalFilename: loopData.filename,\n    originalIndex: loopData.index\n  },\n  binary: currentItem.binary\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "711fea9d-9b12-48cb-b66f-2fa75b014142",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1568,
        -976
      ],
      "parameters": {
        "color": 4,
        "width": 304,
        "height": 368,
        "content": "## Information\n\nThis Node will Upscale Multiple Pictures from A Dataspace in Airtable \n\n1. it will create A folder in Drive\n2. it will take pictures stored in the airtable Dataspace\n3. It will run over Items to upscale in Replicate the pictures\n4. It will store the pictures in Drive\n\nPlease Upload the Pictures in Airtable in a column: PortraitFotoAuswahl "
      },
      "typeVersion": 1
    },
    {
      "id": "97297413-8022-4966-8117-944edf4736fc",
      "name": "Get Record from Pictures",
      "type": "n8n-nodes-base.airtable",
      "position": [
        -496,
        -848
      ],
      "parameters": {
        "id": "=< enter Record ID >",
        "base": {
          "__rl": true,
          "mode": "id",
          "value": ""
        },
        "table": {
          "__rl": true,
          "mode": "id",
          "value": ""
        },
        "options": {}
      },
      "credentials": {
        "airtableTokenApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "45e45d37-8afc-48a2-ab4b-557b985c9741",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -576,
        -960
      ],
      "parameters": {
        "height": 352,
        "content": "## Enter Record from Stored Data\n"
      },
      "typeVersion": 1
    },
    {
      "id": "73b660f8-f518-42d8-8970-234a956f412a",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -832,
        -960
      ],
      "parameters": {
        "height": 352,
        "content": "##  Add Folder Name"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Create folder": {
      "main": [
        [
          {
            "node": "Get Record from Pictures",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Replicate Upscaler",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Upscale": {
      "main": [
        [
          {
            "node": "Set GDrive Upload Folder ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Replicate Upscaler": {
      "main": [
        [
          {
            "node": "Download Upscale",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload to Google Drive": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Record from Pictures": {
      "main": [
        [
          {
            "node": "Extract Portrait URLS from Airtable Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set GDrive Upload Folder ID": {
      "main": [
        [
          {
            "node": "Upload to Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Create folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Portrait URLS from Airtable Output": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}