{
  "name": "Sora/Veo output URL \u2192 TokPortal upload + schedule",
  "nodes": [
    {
      "parameters": {
        "content": "## AI video (Sora / Veo / Runway) \u2192 TokPortal\nStart from a webhook that receives your generator output (`video_url`, `caption`, optional `bundle_id`, `position`, `publish_date`).\n\nThe video is **imported into TokPortal storage** through the presigned upload flow (download \u2192 PUT to R2), so the temporary generator URL can expire safely. Then the slot is configured and published.",
        "height": 260,
        "width": 640,
        "color": 4
      },
      "id": "tp-041",
      "name": "Sticky Notetp-040",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -300
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "ai-video-ready",
        "options": {}
      },
      "id": "tp-042",
      "name": "Generator Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        60
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a1",
              "name": "video_url",
              "value": "={{ $json.body.video_url }}",
              "type": "string"
            },
            {
              "id": "a2",
              "name": "caption",
              "value": "={{ $json.body.caption || \"Made with AI #ai\" }}",
              "type": "string"
            },
            {
              "id": "a3",
              "name": "bundle_id",
              "value": "={{ $json.body.bundle_id || \"REPLACE_WITH_BUNDLE_ID\" }}",
              "type": "string"
            },
            {
              "id": "a4",
              "name": "position",
              "value": "={{ Number($json.body.position || 1) }}",
              "type": "number"
            },
            {
              "id": "a5",
              "name": "publish_date",
              "value": "={{ $json.body.publish_date || $now.plus({ days: 1 }).toFormat(\"yyyy-LL-dd\") }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "tp-043",
      "name": "Normalize Input",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        60
      ]
    },
    {
      "parameters": {
        "resource": "media",
        "operation": "createVideoUploadUrl",
        "bundleId": "={{ $json.bundle_id }}",
        "filename": "={{ \"ai-\" + $now.toMillis() + \".mp4\" }}",
        "contentType": "video/mp4"
      },
      "id": "tp-044",
      "name": "Create Video Upload URL",
      "type": "n8n-nodes-tokportal.tokPortal",
      "typeVersion": 1,
      "position": [
        440,
        60
      ],
      "credentials": {
        "tokPortalApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "GET",
        "url": "={{ $(\"Normalize Input\").item.json.video_url }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "id": "tp-045",
      "name": "Download Generated Video",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        660,
        60
      ]
    },
    {
      "parameters": {
        "method": "={{ $(\"Create Video Upload URL\").item.json.method || \"PUT\" }}",
        "url": "={{ $(\"Create Video Upload URL\").item.json.upload_url }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "video/mp4"
            }
          ]
        },
        "sendBody": true,
        "contentType": "binaryData",
        "inputDataFieldName": "data",
        "options": {}
      },
      "id": "tp-046",
      "name": "PUT to TokPortal Storage",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        60
      ]
    },
    {
      "parameters": {
        "resource": "video",
        "operation": "configure",
        "bundleId": "={{ $(\"Normalize Input\").item.json.bundle_id }}",
        "position": "={{ $(\"Normalize Input\").item.json.position }}",
        "videoType": "video",
        "targetPublishDate": "={{ $(\"Normalize Input\").item.json.publish_date }}",
        "videoUrl": "={{ $(\"Create Video Upload URL\").item.json.public_url }}",
        "description": "={{ $(\"Normalize Input\").item.json.caption }}",
        "additionalFields": {
          "ai_content_disclaimer": true,
          "auto_publish": true
        }
      },
      "id": "tp-047",
      "name": "Configure Video Slot",
      "type": "n8n-nodes-tokportal.tokPortal",
      "typeVersion": 1,
      "position": [
        1100,
        60
      ],
      "credentials": {
        "tokPortalApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Generator Webhook": {
      "main": [
        [
          {
            "node": "Normalize Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Input": {
      "main": [
        [
          {
            "node": "Create Video Upload URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Video Upload URL": {
      "main": [
        [
          {
            "node": "Download Generated Video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Generated Video": {
      "main": [
        [
          {
            "node": "PUT to TokPortal Storage",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "PUT to TokPortal Storage": {
      "main": [
        [
          {
            "node": "Configure Video Slot",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": [
    {
      "name": "TokPortal"
    }
  ]
}