{
  "name": "r2-Sunday-URL-Refresh-Active",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtHour": 5,
              "triggerAtMinute": null
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        0,
        0
      ],
      "id": "b051e002-0154-4333-a055-fa9d89039d6e",
      "name": "Schedule: Sunday 01:00"
    },
    {
      "parameters": {
        "operation": "getAll",
        "tableId": "intake",
        "limit": 1,
        "filters": {
          "conditions": [
            {
              "keyName": "status",
              "condition": "eq",
              "keyValue": "=active"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        240,
        0
      ],
      "id": "b46ccd7a-b48a-4252-8e4a-a6d2ec28a6fc",
      "name": "Supabase: Get Intake Stage",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const mediaItems = $input.all();\nconst intakeItems = $('Code: Extract Intake IDs').all();\n\nconst activeIntakeIds = new Set(intakeItems.map(i => i.json.intake_id));\n\nreturn mediaItems\n  .filter(item => activeIntakeIds.has(item.json.intake_id))\n  .map(item => ({\n    json: {\n      id: item.json.id,\n      intake_id: item.json.intake_id,\n      r2_object_key: item.json.r2_object_key\n    }\n  }));"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        864,
        0
      ],
      "id": "86f0f0a2-0edb-4a4a-b7ee-89269b135b78",
      "name": "Code: Filter by Active Intake IDs"
    },
    {
      "parameters": {
        "jsCode": "const items = $input.all();\n\nreturn items.map(item => ({\n  json: {\n    ...item.json,\n    expiry_seconds: 604800\n  }\n}));"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1072,
        0
      ],
      "id": "c86cd30c-90a9-41ef-a18a-0dc75dca0c16",
      "name": "Code: Determine Expiry"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://spx-r2-signer.spexai.workers.dev/sign",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"r2_object_key\": \"{{ $json.r2_object_key }}\",\n  \"expiry_seconds\": {{ $json.expiry_seconds }}\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        1280,
        0
      ],
      "id": "350611cb-feb1-4b9b-8d7e-0d4eb4f2bf66",
      "name": "HTTP Request",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "tableId": "media_forensics",
        "filters": {
          "conditions": [
            {
              "keyName": "id",
              "condition": "eq",
              "keyValue": "={{ $('Code: Filter by Active Intake IDs').item.json.id }}"
            }
          ]
        },
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "retool_signed_url",
              "fieldValue": "={{ $json.retool_signed_url }}"
            },
            {
              "fieldId": "retool_url_expires_at",
              "fieldValue": "={{ $json.retool_url_expires_at }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        1488,
        0
      ],
      "id": "c218a1a9-a250-44e4-9599-db54dd31a6af",
      "name": "Supabase: Update Signed URL",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const items = $input.all();\n\nreturn items.map(item => ({\n  json: {\n    intake_id: item.json.intake_id\n  }\n}));"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        448,
        0
      ],
      "id": "18fdd7d0-a675-40d1-8f9c-f1c9beb88326",
      "name": "Code: Extract Intake IDs"
    },
    {
      "parameters": {
        "operation": "getAll",
        "tableId": "media_forensics",
        "returnAll": true,
        "filters": {
          "conditions": [
            {
              "keyName": "retool_url_expires_at",
              "condition": "lte",
              "keyValue": "={{ DateTime.now().plus({days: 8}).toISO() }}"
            },
            {
              "keyName": "retool_url_expires_at",
              "condition": "is",
              "keyValue": "null"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        656,
        0
      ],
      "id": "3c424094-e67c-4ba8-b73d-4e99d1bce422",
      "name": "Supabase: Get Expiring URLs",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        192
      ],
      "id": "43fe35c2-fdec-4906-b58f-5adb43f94083",
      "name": "When clicking \u2018Execute workflow\u2019"
    }
  ],
  "connections": {
    "Schedule: Sunday 01:00": {
      "main": [
        [
          {
            "node": "Supabase: Get Intake Stage",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Supabase: Get Intake Stage": {
      "main": [
        [
          {
            "node": "Code: Extract Intake IDs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code: Filter by Active Intake IDs": {
      "main": [
        [
          {
            "node": "Code: Determine Expiry",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code: Determine Expiry": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Supabase: Update Signed URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code: Extract Intake IDs": {
      "main": [
        [
          {
            "node": "Supabase: Get Expiring URLs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Supabase: Get Expiring URLs": {
      "main": [
        [
          {
            "node": "Code: Filter by Active Intake IDs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Supabase: Get Intake Stage",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  },
  "versionId": "b584fe0e-4084-4c04-bd4f-9764777ba1a2",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "tvQkb6TdWJEbMtHV",
  "tags": [
    {
      "updatedAt": "2026-04-11T17:19:07.684Z",
      "createdAt": "2026-04-11T17:19:07.684Z",
      "id": "0kHDvaC4AFK5HWaF",
      "name": "systems_update"
    },
    {
      "updatedAt": "2026-04-07T05:54:12.040Z",
      "createdAt": "2026-04-07T05:54:12.040Z",
      "id": "3ctqgxjHRVbu8uPR",
      "name": "noir-test"
    },
    {
      "updatedAt": "2026-04-07T05:54:41.309Z",
      "createdAt": "2026-04-07T05:54:41.309Z",
      "id": "617SY1s5iJZzmnko",
      "name": "noir-collective-france"
    },
    {
      "updatedAt": "2026-04-07T05:54:15.456Z",
      "createdAt": "2026-04-07T05:54:15.456Z",
      "id": "U5Z5J0HkLxUQA5hK",
      "name": "prototype"
    },
    {
      "updatedAt": "2026-04-11T17:19:17.815Z",
      "createdAt": "2026-04-11T17:19:17.815Z",
      "id": "n69dqzL4kSMo9qoo",
      "name": "maintainence"
    }
  ]
}