{
  "name": "Drive to Data_Driven Sheet",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 6
            }
          ]
        }
      },
      "id": "a1b2c3d4-0001-0001-0001-000000000001",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        180,
        300
      ]
    },
    {
      "parameters": {
        "resource": "fileFolder",
        "operation": "search",
        "queryString": "'BUNDLES_FOLDER_ID' in parents and trashed = false and mimeType = 'application/vnd.google-apps.folder'",
        "returnAll": true,
        "options": {
          "fields": "id,name,mimeType,webViewLink"
        }
      },
      "id": "a1b2c3d4-0002-0002-0002-000000000002",
      "name": "List Bundle Folders",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        400,
        300
      ]
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "id": "a1b2c3d4-0003-0003-0003-000000000003",
      "name": "Loop Folders",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        620,
        300
      ]
    },
    {
      "parameters": {
        "resource": "fileFolder",
        "operation": "search",
        "queryString": "={{ $json.id + ' in parents and trashed = false'}}",
        "returnAll": true,
        "options": {
          "fields": "id,name,mimeType,webViewLink,thumbnailLink"
        }
      },
      "id": "a1b2c3d4-0004-0004-0004-000000000004",
      "name": "List Bundle Children",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        840,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const items = $input.all();\nconst bundle = $('Loop Folders').item.json;\nlet thumbnails_folder_id = '';\nlet download_link = '';\nlet zip_name = '';\nfor (const item of items) {\n  const f = item.json;\n  const name = (f.name || '').toLowerCase();\n  const mime = f.mimeType || '';\n  if (mime === 'application/vnd.google-apps.folder' && name === 'thumnails') {\n    thumbnails_folder_id = f.id;\n  }\n  if (name.endsWith('.zip')) {\n    zip_name = f.name;\n    download_link = f.webViewLink || 'https://drive.google.com/file/d/' + f.id + '/view';\n  }\n}\nreturn [{ json: { folder_name: bundle.name, folder_id: bundle.id, thumbnails_folder_id, zip_name, download_link } }];"
      },
      "id": "a1b2c3d4-0005-0005-0005-000000000005",
      "name": "Extract Assets",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1060,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "cond1",
              "leftValue": "={{ $json.thumbnails_folder_id }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "a1b2c3d4-0006-0006-0006-000000000006",
      "name": "Has Thumbnails Folder?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        1280,
        300
      ]
    },
    {
      "parameters": {
        "resource": "fileFolder",
        "operation": "search",
        "queryString": "={{ $json.thumbnails_folder_id + ' in parents and trashed = false'}}",
        "returnAll": true,
        "options": {
          "fields": "id,name,mimeType,webViewLink,thumbnailLink"
        }
      },
      "id": "a1b2c3d4-0007-0007-0007-000000000007",
      "name": "List Thumbnail Images",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        1500,
        200
      ]
    },
    {
      "parameters": {
        "jsCode": "const imageItems = $input.all();\nconst base = $('Extract Assets').item.json;\nconst thumbnails = imageItems.filter(item => { const f = item.json; const mime = f.mimeType || ''; const name = (f.name || '').toLowerCase(); return mime.startsWith('image/') || name.endsWith('.jpg') || name.endsWith('.jpeg') || name.endsWith('.png') || name.endsWith('.webp'); }).map(item => { const f = item.json; return f.thumbnailLink || f.webViewLink || 'https://drive.google.com/file/d/' + f.id + '/view'; });\nreturn [{ json: { title: base.folder_name, folder_id: base.folder_id, thumbnails: thumbnails.join(' | '), download_link: base.download_link } }];"
      },
      "id": "a1b2c3d4-0008-0008-0008-000000000008",
      "name": "Build Sheet Row",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1720,
        200
      ]
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "value": "YOUR_GOOGLE_SHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Data_Driven",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "title": "={{ $json.title }}",
            "folder_id": "={{ $json.folder_id }}",
            "thumbnails": "={{ $json.thumbnails }}",
            "download_link": "={{ $json.download_link }}"
          },
          "matchingColumns": [
            "folder_id"
          ],
          "schema": [
            {
              "id": "title",
              "displayName": "title",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "folder_id",
              "displayName": "folder_id",
              "required": false,
              "defaultMatch": true,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "thumbnails",
              "displayName": "thumbnails",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "download_link",
              "displayName": "download_link",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {}
      },
      "id": "a1b2c3d4-0009-0009-0009-000000000009",
      "name": "Upsert to Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        1940,
        200
      ]
    },
    {
      "parameters": {
        "jsCode": "const base = $('Extract Assets').item.json;\nreturn [{ json: { title: base.folder_name, folder_id: base.folder_id, thumbnails: '', download_link: base.download_link } }];"
      },
      "id": "a1b2c3d4-0010-0010-0010-000000000010",
      "name": "No Thumbnails Row",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1500,
        420
      ]
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "value": "YOUR_GOOGLE_SHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Data_Driven",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "title": "={{ $json.title }}",
            "folder_id": "={{ $json.folder_id }}",
            "thumbnails": "={{ $json.thumbnails }}",
            "download_link": "={{ $json.download_link }}"
          },
          "matchingColumns": [
            "folder_id"
          ],
          "schema": [
            {
              "id": "title",
              "displayName": "title",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "folder_id",
              "displayName": "folder_id",
              "required": false,
              "defaultMatch": true,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "thumbnails",
              "displayName": "thumbnails",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "download_link",
              "displayName": "download_link",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {}
      },
      "id": "a1b2c3d4-0011-0011-0011-000000000011",
      "name": "Upsert No Thumbs",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        1720,
        420
      ]
    }
  ],
  "connections": {
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "List Bundle Folders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List Bundle Folders": {
      "main": [
        [
          {
            "node": "Loop Folders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Folders": {
      "main": [
        [
          {
            "node": "List Bundle Children",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List Bundle Children": {
      "main": [
        [
          {
            "node": "Extract Assets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Assets": {
      "main": [
        [
          {
            "node": "Has Thumbnails Folder?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Thumbnails Folder?": {
      "main": [
        [
          {
            "node": "List Thumbnail Images",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Thumbnails Row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List Thumbnail Images": {
      "main": [
        [
          {
            "node": "Build Sheet Row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Sheet Row": {
      "main": [
        [
          {
            "node": "Upsert to Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upsert to Sheet": {
      "main": [
        [
          {
            "node": "Loop Folders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "No Thumbnails Row": {
      "main": [
        [
          {
            "node": "Upsert No Thumbs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upsert No Thumbs": {
      "main": [
        [
          {
            "node": "Loop Folders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "active": false
}