{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "3fce381a-7ffe-4d58-868b-b1b6e48372eb",
      "name": "Trigger: Weekly Archive Scan",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        0,
        560
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "16890e81-bd46-4148-b986-a8cb62c6fa42",
      "name": "List Active Project Files",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        224,
        560
      ],
      "parameters": {
        "resource": "folder",
        "operation": "list"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "fc4eb058-7684-4268-b8b9-4e9707d79e8d",
      "name": "Calculate File Age (Luxon Logic)",
      "type": "n8n-nodes-base.code",
      "position": [
        448,
        560
      ],
      "parameters": {
        "jsCode": "const item = $input.first().json;\nconst modifiedDate = new Date(item.modifiedTime);\nconst sixMonthsAgo = new Date();\nsixMonthsAgo.setMonth(sixMonthsAgo.getMonth() - 6);\n\nitem.isReadyForArchive = (modifiedDate < sixMonthsAgo);\nitem.archivePath = `archives/${new Date().getFullYear()}/${new Date().getMonth() + 1}`;\nreturn { json: item };"
      },
      "typeVersion": 2
    },
    {
      "id": "863eaa18-44ea-471e-a4cd-42301ab8943a",
      "name": "IF: Meets Archive Criteria?",
      "type": "n8n-nodes-base.if",
      "position": [
        672,
        560
      ],
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.isReadyForArchive }}"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f50e4604-ce15-40f6-930d-2cba5c56c6e0",
      "name": "Download Hot Storage Binary",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        880,
        464
      ],
      "parameters": {
        "fileId": "={{ $json.id }}",
        "options": {},
        "operation": "download"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "888e6598-8df6-48d0-abbe-26de56fdac07",
      "name": "Compress PDF for Archival",
      "type": "n8n-nodes-htmlcsstopdf.htmlcsstopdf",
      "position": [
        1104,
        464
      ],
      "parameters": {
        "resource": "pdfManipulation",
        "operation": "compress"
      },
      "credentials": {
        "htmlcsstopdfApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "644f0e02-f743-4fe5-ae5d-407558215bdc",
      "name": "Upload to Cold Storage (S3)",
      "type": "n8n-nodes-base.s3",
      "position": [
        1328,
        464
      ],
      "parameters": {
        "fileKey": "2",
        "bucketName": "project-archives-cold"
      },
      "credentials": {
        "s3": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "388067a0-49e2-48e1-b052-232a53344837",
      "name": "Log Savings to Slack",
      "type": "n8n-nodes-base.slack",
      "position": [
        1552,
        464
      ],
      "parameters": {
        "text": "=\ud83d\udce6 *Storage Optimization Report*\n\nProject file `{{ $node[\"List Active Project Files\"].json.name }}` was compressed and migrated to cold storage.\n\nPath: `{{ $node[\"Calculate File Age (Luxon Logic)\"].json.archivePath }}`",
        "user": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "select": "user",
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "credentials": {
        "slackOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "9d01e42f-e0fe-4c30-958a-6992dfe34b91",
      "name": "Main Documentation",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "parameters": {
        "width": 500,
        "height": 450,
        "content": "## How it works\nThis workflow manages document lifecycles. It triggers weekly to scan Google Drive for files modified over 6 months ago. A Code node calculates the \"Age Gate\" and generates a dynamic archive path using Luxon. Aging files are downloaded, compressed via the HTML to PDF node to save space, and uploaded to AWS S3. A Slack report confirms the migration to the IT team.\n\n## Setup steps\n1. **Google Drive**: Connect your account and select your \"Hot Storage\" folder.\n2. **Logic**: Adjust the month threshold in the Code node (default: 6 months).\n3. **Compression**: Ensure your HTML to PDF API credentials are active.\n4. **AWS S3**: Enter your bucket name and access credentials for your \"Cold Storage\".\n5. **Slack**: Authenticate to enable weekly storage optimization reports."
      },
      "typeVersion": 1
    },
    {
      "id": "9b5c1376-fb33-4299-aaf6-9ac895ab2997",
      "name": "Processing Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        848,
        336
      ],
      "parameters": {
        "color": 7,
        "width": 800,
        "height": 380,
        "content": "### \ud83d\udee0\ufe0f Optimization & Migration Logic\nGrouped nodes for data compression, integrity verification, and S3 cloud migration."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Compress PDF for Archival": {
      "main": [
        [
          {
            "node": "Upload to Cold Storage (S3)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List Active Project Files": {
      "main": [
        [
          {
            "node": "Calculate File Age (Luxon Logic)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Hot Storage Binary": {
      "main": [
        [
          {
            "node": "Compress PDF for Archival",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF: Meets Archive Criteria?": {
      "main": [
        [
          {
            "node": "Download Hot Storage Binary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload to Cold Storage (S3)": {
      "main": [
        [
          {
            "node": "Log Savings to Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trigger: Weekly Archive Scan": {
      "main": [
        [
          {
            "node": "List Active Project Files",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate File Age (Luxon Logic)": {
      "main": [
        [
          {
            "node": "IF: Meets Archive Criteria?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}