{
  "name": "file manager",
  "nodes": [
    {
      "parameters": {
        "operation": "upload",
        "bucketName": "BUCKET_NAME",
        "fileName": "={{ $('When Executed by Another Workflow').item.json.workspace_id }}/{{ $json.fileName }}",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.s3",
      "typeVersion": 1,
      "position": [
        496,
        -352
      ],
      "id": "0038e792-ddfe-40a1-b119-4efdaba2e65f",
      "name": "Upload a file",
      "notesInFlow": false,
      "credentials": {
        "s3": {
          "name": "<your credential>"
        }
      },
      "notes": "the bucket must have file lock and versioning disabled!"
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "textsWithManipulations": {
          "textsWithManipulationsValues": [
            {
              "dataSources": {
                "dataSource": [
                  {
                    "text": "={{ $json.extractedText }}",
                    "destinationKey": "html"
                  }
                ]
              },
              "manipulations": {
                "manipulation": [
                  {
                    "action": "replace",
                    "substring": "images/",
                    "value": "=https://CDN_DOMAIN/{{ $('When Executed by Another Workflow').item.json.workspace_id }}/"
                  }
                ]
              }
            }
          ]
        }
      },
      "type": "n8n-nodes-text-manipulation.textManipulation",
      "typeVersion": 1,
      "position": [
        720,
        -224
      ],
      "id": "2eb84315-389a-4fb0-a479-9f65a5e716fa",
      "name": "TextManipulation"
    },
    {
      "parameters": {
        "jsCode": "const output = [];\n\nfor (const item of $input.all()) {\n  for (const key of Object.keys(item.binary ?? {})) {\n    output.push({\n      json: {\n        fileName: item.binary[key].fileName,\n        mimeType: item.binary[key].mimeType,\n      },\n      binary: {\n        data: item.binary[key],\n      },\n    });\n  }\n}\n\nreturn output;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        128,
        -288
      ],
      "id": "fcf45308-f80d-474b-bc5b-970050a7848e",
      "name": "Split files"
    },
    {
      "parameters": {
        "binaryPropertyName": "zip"
      },
      "type": "n8n-nodes-base.compression",
      "typeVersion": 1.1,
      "position": [
        -64,
        -288
      ],
      "id": "4b19a047-3e00-49df-8841-4158141323d5",
      "name": "Unzip"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "6a51e94f-a80c-4c03-b23d-1224b70ddae7",
              "leftValue": "={{ $json.fileName }}",
              "rightValue": "/\\.(jpg|jpeg|png|webp|gif)$/i",
              "operator": {
                "type": "string",
                "operation": "regex"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.3,
      "position": [
        320,
        -352
      ],
      "id": "c3d8a037-24d9-4fc7-9e01-b68d3446018a",
      "name": "Only images"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "660e288a-bdb9-45bb-9ec2-58fb0f9b0b30",
              "leftValue": "={{ $json.fileName }}",
              "rightValue": "email.html",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.3,
      "position": [
        320,
        -192
      ],
      "id": "52219ef2-c352-482b-8402-2f68dfe1d91b",
      "name": "Only HTML"
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const buffer = await this.helpers.getBinaryDataBuffer(0, 'data');\n\nconst textContent = buffer.toString('utf8');\n\nreturn {\n  json: {\n    extractedText: textContent\n  }\n};"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        496,
        -192
      ],
      "id": "168510de-1691-4788-863e-9a01a6988e52",
      "name": "Binary to String"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://MJML_SERVICE_DOMAIN/html-to-mjml",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "contentType": "raw",
        "rawContentType": "text/html",
        "body": "={{ $json.html }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        976,
        -368
      ],
      "id": "4dd63e7f-9367-412c-a4ba-65769bf05364",
      "name": "HTML to MJML (json)",
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://MJML_SERVICE_DOMAIN/html-to-mjml",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/xml"
            }
          ]
        },
        "sendBody": true,
        "contentType": "raw",
        "rawContentType": "text/html",
        "body": "={{ $json.html }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        976,
        -224
      ],
      "id": "49022acb-5979-4baf-991c-d6b093591bb6",
      "name": "HTML to MJML (xml)",
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "inputSource": "passthrough"
      },
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        -256,
        -288
      ],
      "id": "d1b751a0-d2c4-457b-9102-3c2434afa21f",
      "name": "When Executed by Another Workflow"
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineAll",
        "options": {}
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        1216,
        -288
      ],
      "id": "8115c493-4d49-40f1-a66b-1072d8347008",
      "name": "Merge"
    }
  ],
  "connections": {
    "TextManipulation": {
      "main": [
        [
          {
            "node": "HTML to MJML (json)",
            "type": "main",
            "index": 0
          },
          {
            "node": "HTML to MJML (xml)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Unzip": {
      "main": [
        [
          {
            "node": "Split files",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split files": {
      "main": [
        [
          {
            "node": "Only images",
            "type": "main",
            "index": 0
          },
          {
            "node": "Only HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Only images": {
      "main": [
        [
          {
            "node": "Upload a file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Only HTML": {
      "main": [
        [
          {
            "node": "Binary to String",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Binary to String": {
      "main": [
        [
          {
            "node": "TextManipulation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML to MJML (xml)": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Unzip",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML to MJML (json)": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        []
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "timeSavedMode": "fixed",
    "callerPolicy": "workflowsFromSameOwner",
    "availableInMCP": false,
    "saveDataSuccessExecution": "none"
  },
  "versionId": "42d3b597-93bc-4d9c-ad6a-b8894ded0329",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "YHo1opOPxowH9B9Z",
  "tags": []
}