{
  "name": "Google Drive asset check and catalog",
  "nodes": [
    {
      "id": "e7023b3a-9471-4cee-8608-1255390071e6",
      "name": "Read me first",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -688,
        -240
      ],
      "parameters": {
        "content": "## Google Drive asset check and catalog\nEach new file in your Drive inbox folder is checked. Good files move to Ready and join a catalog sheet. The rest move to Needs fixing and you get the reason.\n\n### You need\n- A Google Drive login and 3 folders: Inbox, Ready, Needs fixing\n- A Google Sheets login and an Asset Catalog tab with: File ID, Name, Type, Size MB, Description, Link, Status, Problems, Checked At\n- A Telegram bot and your chat ID\n\n### Set it up\n1. In **New file in the inbox**, pick your Inbox folder. Pick Ready in **Move to Ready** and Needs fixing in **Move to Needs fixing**.\n2. Pick your sheet in the 3 Google Sheets steps.\n3. In **Settings**, add your chat ID and the biggest file size you accept, in MB.\n4. Failure alert: put your chat ID in **Write the failure alert** and your bot in **Send the failure alert**. Then in Workflow settings, set Error workflow to this workflow.\n\n### Test it\n- Turn the workflow on. Drop a photo with a description, and a file with no extension, in the Inbox folder.\n- The photo moves to Ready and gets a catalog row. The other moves to Needs fixing and you get a message.",
        "height": 832,
        "width": 560,
        "color": 4
      }
    },
    {
      "id": "a30e4c34-6f61-4284-a524-c105011640a6",
      "name": "Note: check",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -48,
        -120
      ],
      "parameters": {
        "content": "## Check the file\nA file needs a name with an extension, a photo or video type, a size under the limit and a description. A name already in the catalog is flagged too.",
        "height": 540,
        "width": 1000,
        "color": 7
      }
    },
    {
      "id": "1e436d26-51ae-48a9-973e-a6c5391ce600",
      "name": "Note: file it",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1032,
        -240
      ],
      "parameters": {
        "content": "## File it\nReady files move and get a catalog row. Files that need fixing move and you get the reason. Nothing is deleted.",
        "height": 1060,
        "width": 760,
        "color": 7
      }
    },
    {
      "id": "2ac8a0a5-5239-4205-b75a-d08ddd907f1f",
      "name": "New file in the inbox",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "typeVersion": 1,
      "position": [
        0,
        100
      ],
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "value": "",
          "mode": "list"
        },
        "event": "fileCreated",
        "options": {}
      }
    },
    {
      "id": "cb3af941-7faa-4b05-a43c-ed63adc84599",
      "name": "Settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        100
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "f1",
              "name": "maxSizeMB",
              "type": "number",
              "value": 100
            },
            {
              "id": "f2",
              "name": "telegramChatId",
              "type": "string",
              "value": "YOUR_CHAT_ID"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      }
    },
    {
      "id": "59ed663d-851c-48a9-91cf-6789caa428f3",
      "name": "Read the catalog",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        480,
        100
      ],
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "value": "",
          "mode": "url"
        },
        "sheetName": {
          "__rl": true,
          "value": "Asset Catalog",
          "mode": "name"
        },
        "options": {}
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "31cca3e2-c533-4526-9bbe-85ffd1729ae5",
      "name": "Check the file",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        720,
        100
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const s = $('Settings').first().json;\nconst known = new Set($('Read the catalog').all().filter(r => r.json.Status === 'Ready').map(r => String(r.json.Name || '').trim().toLowerCase()));\nreturn $('New file in the inbox').all().map(({ json: f }) => {\n  const problems = [];\n  const name = String(f.name || '');\n  const type = String(f.mimeType || '');\n  const sizeMB = f.size === undefined || f.size === null || f.size === '' ? null : Number(f.size) / 1048576;\n  if (!/\\.[a-z0-9]{2,5}$/i.test(name)) problems.push('The name has no file ending, like .jpg or .mp4.');\n  if (!type.startsWith('image/') && !type.startsWith('video/')) problems.push('It is not a photo or a video (' + (type || 'unknown type') + ').');\n  if (sizeMB !== null && sizeMB <= 0) problems.push('The file is empty.');\n  if (sizeMB !== null && sizeMB > Number(s.maxSizeMB || 100)) problems.push('It is ' + sizeMB.toFixed(1) + ' MB. The limit is ' + s.maxSizeMB + ' MB.');\n  if (!String(f.description || '').trim()) problems.push('It has no description. Add one in Drive (right click, File information).');\n  if (known.has(name.trim().toLowerCase())) problems.push('A file with this name is already in the catalog.');\n  return { json: {\n    fileId: f.id, name, type, sizeMB: sizeMB === null ? '' : Number(sizeMB.toFixed(2)), description: String(f.description || '').trim(),\n    link: 'https://drive.google.com/file/d/' + f.id + '/view', ready: problems.length === 0, problems: problems.join(' '),\n  } };\n});"
      }
    },
    {
      "id": "ca8e8c3b-ef64-465a-be3d-8e68fc5724bf",
      "name": "Ready?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        960,
        100
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.ready === true }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      }
    },
    {
      "id": "05ca2eee-9282-415f-853f-2cdea0b4d897",
      "name": "Move to Ready",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        1200,
        -40
      ],
      "parameters": {
        "operation": "move",
        "fileId": {
          "__rl": true,
          "value": "={{ $json.fileId }}",
          "mode": "id"
        },
        "driveId": {
          "__rl": true,
          "value": "My Drive",
          "mode": "list"
        },
        "folderId": {
          "__rl": true,
          "value": "",
          "mode": "list"
        }
      }
    },
    {
      "id": "6063f89d-bda6-4035-8872-c3b167551ed0",
      "name": "Add to the catalog",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1440,
        -40
      ],
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "",
          "mode": "url"
        },
        "sheetName": {
          "__rl": true,
          "value": "Asset Catalog",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "File ID": "={{ $('Check the file').item.json.fileId }}",
            "Name": "={{ $('Check the file').item.json.name }}",
            "Type": "={{ $('Check the file').item.json.type }}",
            "Size MB": "={{ $('Check the file').item.json.sizeMB }}",
            "Description": "={{ $('Check the file').item.json.description }}",
            "Link": "={{ $('Check the file').item.json.link }}",
            "Status": "Ready",
            "Problems": "",
            "Checked At": "={{ $now.toISO() }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "File ID",
              "displayName": "File ID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Name",
              "displayName": "Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Type",
              "displayName": "Type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Size MB",
              "displayName": "Size MB",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Description",
              "displayName": "Description",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Link",
              "displayName": "Link",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Status",
              "displayName": "Status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Problems",
              "displayName": "Problems",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Checked At",
              "displayName": "Checked At",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "f3e850d2-e8ca-4b58-9087-65f35dbced3e",
      "name": "Move to Needs fixing",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        1200,
        240
      ],
      "parameters": {
        "operation": "move",
        "fileId": {
          "__rl": true,
          "value": "={{ $json.fileId }}",
          "mode": "id"
        },
        "driveId": {
          "__rl": true,
          "value": "My Drive",
          "mode": "list"
        },
        "folderId": {
          "__rl": true,
          "value": "",
          "mode": "list"
        }
      }
    },
    {
      "id": "97dfd600-a767-4890-bc9e-6081cfe00a9a",
      "name": "Log what needs fixing",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1440,
        240
      ],
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "",
          "mode": "url"
        },
        "sheetName": {
          "__rl": true,
          "value": "Asset Catalog",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "File ID": "={{ $('Check the file').item.json.fileId }}",
            "Name": "={{ $('Check the file').item.json.name }}",
            "Type": "={{ $('Check the file').item.json.type }}",
            "Size MB": "={{ $('Check the file').item.json.sizeMB }}",
            "Description": "={{ $('Check the file').item.json.description }}",
            "Link": "={{ $('Check the file').item.json.link }}",
            "Status": "Needs fixing",
            "Problems": "={{ $('Check the file').item.json.problems }}",
            "Checked At": "={{ $now.toISO() }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "File ID",
              "displayName": "File ID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Name",
              "displayName": "Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Type",
              "displayName": "Type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Size MB",
              "displayName": "Size MB",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Description",
              "displayName": "Description",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Link",
              "displayName": "Link",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Status",
              "displayName": "Status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Problems",
              "displayName": "Problems",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Checked At",
              "displayName": "Checked At",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "13c81bfb-4116-4dcd-9dc9-e7a1d7c081c1",
      "name": "Tell you what to fix",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1680,
        240
      ],
      "parameters": {
        "chatId": "={{ $('Settings').first().json.telegramChatId }}",
        "text": "={{ 'A file needs fixing: ' + $('Check the file').item.json.name + '\\n\\n' + $('Check the file').item.json.problems + '\\n\\nIt is in your Needs fixing folder: ' + $('Check the file').item.json.link }}",
        "additionalFields": {
          "appendAttribution": false
        }
      }
    },
    {
      "id": "0930b652-d819-4359-92b9-7e4880e58bd6",
      "name": "When this workflow fails",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [
        -648,
        672
      ],
      "parameters": {}
    },
    {
      "id": "f9300618-a8e7-4f7c-8ef0-ad1d17291d62",
      "name": "Write the failure alert",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -428,
        672
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "f1",
              "name": "telegramChatId",
              "type": "string",
              "value": "YOUR_TELEGRAM_CHAT_ID"
            },
            {
              "id": "f2",
              "name": "message",
              "type": "string",
              "value": "={{ 'A workflow stopped.\\n\\nWorkflow: ' + (($json.workflow || {}).name || 'unknown') + '\\nFailed step: ' + (($json.execution || {}).lastNodeExecuted || 'unknown') + '\\nWhy: ' + String((($json.execution || {}).error || {}).message || 'n8n did not give a reason.').slice(0, 300) + (($json.execution || {}).url ? '\\nOpen the run: ' + $json.execution.url : '') }}"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      }
    },
    {
      "id": "88266a2c-3673-44db-83ec-d6c5c99a5d05",
      "name": "Send the failure alert",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -208,
        672
      ],
      "parameters": {
        "chatId": "={{ $json.telegramChatId }}",
        "text": "={{ $json.message }}",
        "additionalFields": {
          "appendAttribution": false
        }
      }
    }
  ],
  "connections": {
    "New file in the inbox": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Settings": {
      "main": [
        [
          {
            "node": "Read the catalog",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read the catalog": {
      "main": [
        [
          {
            "node": "Check the file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check the file": {
      "main": [
        [
          {
            "node": "Ready?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ready?": {
      "main": [
        [
          {
            "node": "Move to Ready",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Move to Needs fixing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Move to Ready": {
      "main": [
        [
          {
            "node": "Add to the catalog",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Move to Needs fixing": {
      "main": [
        [
          {
            "node": "Log what needs fixing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log what needs fixing": {
      "main": [
        [
          {
            "node": "Tell you what to fix",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When this workflow fails": {
      "main": [
        [
          {
            "node": "Write the failure alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write the failure alert": {
      "main": [
        [
          {
            "node": "Send the failure alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "tags": []
}
