{
  "updatedAt": "2025-03-21T08:34:22.000Z",
  "createdAt": "2025-01-04T16:28:55.335Z",
  "id": "ITOgH8CMN7U6bMXv",
  "name": "Tìm kiếm ảnh cho bài viết - Subflow",
  "description": null,
  "active": true,
  "isArchived": false,
  "nodes": [
    {
      "parameters": {
        "fieldToSplitOut": "data",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        -20,
        0
      ],
      "id": "9d38b71c-07de-421c-8d00-8ca76d5f74ae",
      "name": "Split Out1"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "4bd1c2bd-327b-49d4-b370-d9110f54bdca",
              "name": "title",
              "value": "={{ $json.title }}",
              "type": "string"
            },
            {
              "id": "1009c406-9b3e-4193-9d2d-a1697143acc4",
              "name": "src",
              "value": "={{ $json.image.source.url }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        200,
        0
      ],
      "id": "e4473df8-3b78-4525-ba38-6de16c32fde2",
      "name": "cleanup"
    },
    {
      "parameters": {
        "fieldToSplitOut": "photos",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        -20,
        -160
      ],
      "id": "5eb8c399-1258-4edb-83ed-33f7a426a316",
      "name": "Split Out2"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "547a770f-66d0-4c07-8099-ec0340a4376a",
              "name": "src",
              "value": "={{ $json.src.large }}",
              "type": "string"
            },
            {
              "id": "0917edb1-37c5-42b6-aca7-094e1a62791f",
              "name": "title",
              "value": "={{ $json.alt }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        -160
      ],
      "id": "e657d412-d230-4626-a307-29a6b7cba04c",
      "name": "cleanup1"
    },
    {
      "parameters": {
        "numberInputs": 3
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [
        1300,
        120
      ],
      "id": "989ac5ac-8c4d-4b11-b1d7-2cf5f25dd8cd",
      "name": "Merge"
    },
    {
      "parameters": {
        "aggregate": "aggregateAllItemData",
        "options": {}
      },
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        1560,
        120
      ],
      "id": "4b3dc39f-3ea5-426f-b1cb-788dffd33f4a",
      "name": "Aggregate"
    },
    {
      "parameters": {
        "jsonSchemaExample": "{\n\t\"title\": \"title\",\n\t\"src\": \"http://link.png\"\n}"
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.2,
      "position": [
        2100,
        280
      ],
      "id": "dbe7ae68-3825-4c9c-9ad1-25ae17b5f9b7",
      "name": "Structured Output Parser"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [
        1780,
        300
      ],
      "id": "6932244c-d763-4267-8b96-316a3db1e2b7",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "id": "hY3IQYAWuJo2IGnB",
          "name": "OpenAi binh"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "79d33a28-a062-4c92-abcc-ca4c9cf324ac",
              "name": "keyword",
              "value": "={{ $json.keyword.trim().split(\" \") }}",
              "type": "array"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        0,
        320
      ],
      "id": "34e71061-7b6f-4220-ba50-1d056cbe6441",
      "name": "splitKeywords"
    },
    {
      "parameters": {
        "fieldToSplitOut": "keyword",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        220,
        320
      ],
      "id": "a118caed-f6f8-40f2-82d4-6993c0fd4c1e",
      "name": "Split Out"
    },
    {
      "parameters": {
        "resource": "fileFolder",
        "queryString": "={{ $json.keyword }}",
        "returnAll": true,
        "filter": {
          "folderId": {
            "__rl": true,
            "value": "={{ $('trigger_search_images').item.json.configs[\"google-drive-photo-folder-url\"] }}",
            "mode": "url"
          },
          "whatToSearch": "files"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        460,
        320
      ],
      "id": "06de8382-c50b-4805-830f-8cc5ca42f39f",
      "name": "search image",
      "retryOnFail": true,
      "waitBetweenTries": 3000,
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "UpcTHbah2DN5nDu8",
          "name": "Google Drive account Mecode"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "965fea22-1894-4dcd-9cb5-2c661ab8884b",
              "leftValue": "={{ $json.configs[\"google-drive-photo-folder-url\"] }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -200,
        340
      ],
      "id": "8ebe3734-ec1a-42a8-97b3-094d8aa22021",
      "name": "If_enable_search_google_drive"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "4bd1c2bd-327b-49d4-b370-d9110f54bdca",
              "name": "title",
              "value": "={{ $json.name.replaceAll(/\\.(png|jpg|gif|jpeg|svg|webp)/g,\"\").trim().replace(\"-\", \" \").replaceAll(\"-\",\" \") }}",
              "type": "string"
            },
            {
              "id": "1009c406-9b3e-4193-9d2d-a1697143acc4",
              "name": "src",
              "value": "=https://{{$('trigger_search_images').item.json.configs.n8n_domain}}/webhook/autopost2-google-drive-get-img.jpg?id={{ $json.id }}&type.jpg",
              "type": "string"
            },
            {
              "id": "09ea779c-6542-446a-a48e-dffa844bdf7b",
              "name": "googledrive",
              "value": true,
              "type": "boolean"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        980,
        320
      ],
      "id": "5a7b033b-6504-4e08-be93-2cb9ab30342c",
      "name": "cleanup2"
    },
    {
      "parameters": {
        "sortFieldsUi": {
          "sortField": [
            {
              "fieldName": "repeat",
              "order": "descending"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.sort",
      "typeVersion": 1,
      "position": [
        780,
        540
      ],
      "id": "1c1f6408-a789-46bc-8002-f8393f7713b4",
      "name": "Sort"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "de7c873a-b254-4c13-b486-8014080d076a",
              "name": "repeat",
              "value": "={{ $json.title.toLowerCase().split(\" \").filter(key => $('trigger_search_images').item.json.keyword.toLowerCase().includes(key)).length }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        380,
        540
      ],
      "id": "413013bf-460c-46e5-b739-f9db70a4410c",
      "name": "setRepeat"
    },
    {
      "parameters": {
        "maxItems": 3
      },
      "type": "n8n-nodes-base.limit",
      "typeVersion": 1,
      "position": [
        980,
        540
      ],
      "id": "3ac289d7-c8d4-4758-b239-6f7146419a7c",
      "name": "Limit_3"
    },
    {
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "alt"
            },
            {
              "name": "title"
            },
            {
              "name": "keyword"
            },
            {
              "name": "require"
            },
            {
              "name": "configs",
              "type": "object"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        -820,
        80
      ],
      "id": "ec5069ae-bc28-46ad-907a-e92b422bd806",
      "name": "trigger_search_images"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "33033fc3-4db3-4fcf-aead-e97d89c84644",
              "leftValue": "={{ $json.configs['google-drive-photo-folder-url'] }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -580,
        140
      ],
      "id": "3c378d2f-2612-431f-a35a-7cf5b2879de4",
      "name": "If_gooogle_drive_folder"
    },
    {
      "parameters": {
        "url": "https://api.freepik.com/v1/resources",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "term",
              "value": "={{ $json.keyword }}"
            },
            {
              "name": "limit",
              "value": "5"
            },
            {
              "name": "filters",
              "value": "={{ \n\n{\n  license: {\n     freemium: 1\n  }\n}\n}}"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-freepik-api-key",
              "value": "={{ $json.configs.freepik_api_key }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -220,
        0
      ],
      "id": "927c9c2b-0571-44ab-85e9-17f3420fa7c4",
      "name": "search_on_freepick",
      "retryOnFail": true,
      "waitBetweenTries": 3000
    },
    {
      "parameters": {
        "url": "https://api.pexels.com/v1/search",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "query",
              "value": "={{ $json.keyword }}"
            },
            {
              "name": "per_page",
              "value": "5"
            },
            {
              "name": "page",
              "value": "1"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "={{ $json.configs.pexels_api_key }}"
            }
          ]
        },
        "options": {
          "redirect": {
            "redirect": {}
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -220,
        -160
      ],
      "id": "94d508c0-2e06-4abe-bb4f-ac550271c9b8",
      "name": "search on pexel",
      "retryOnFail": true,
      "waitBetweenTries": 3000
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "515a3cc2-1d82-477e-846a-cc3f7bee6167",
              "leftValue": "={{ $json.name }}",
              "rightValue": ".png",
              "operator": {
                "type": "string",
                "operation": "endsWith"
              }
            },
            {
              "id": "6d4a900c-5dda-45c5-a9aa-7d67b96123d5",
              "leftValue": "={{ $json.name }}",
              "rightValue": ".jpg",
              "operator": {
                "type": "string",
                "operation": "endsWith"
              }
            },
            {
              "id": "8111be19-fde4-41e3-8dde-f02d31ca78b4",
              "leftValue": "={{ $json.name }}",
              "rightValue": ".jpeg",
              "operator": {
                "type": "string",
                "operation": "endsWith"
              }
            },
            {
              "id": "dea365db-a02c-4807-a6d9-b3fd7039d9ff",
              "leftValue": "={{ $json.name }}",
              "rightValue": ".gif",
              "operator": {
                "type": "string",
                "operation": "endsWith"
              }
            },
            {
              "id": "c6507107-ce28-47be-afae-ba6a17167a08",
              "leftValue": "={{ $json.name }}",
              "rightValue": ".svg",
              "operator": {
                "type": "string",
                "operation": "endsWith"
              }
            }
          ],
          "combinator": "or"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        680,
        320
      ],
      "id": "189427a8-7fa1-4e01-8bb7-785b5fee8d4c",
      "name": "Filter"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Chọn và trả về một item hình theo tiêu chí:  {{ $('trigger_search_images').item.json.require }}\n\n- ưu tiên hình từ google drive vì đó là hình chính chủ của tôi\n\ntừ items hình sau:\n{{ $json.data.toJsonString() }}\nnếu không có kết quả nào phù hợp hãy chọn ngẫu nhiên một item",
        "hasOutputParser": true,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        1820,
        120
      ],
      "id": "6a21e22d-7f02-4572-b55e-c5efcfa148ac",
      "name": "Choose The best image",
      "retryOnFail": true,
      "waitBetweenTries": 5000
    }
  ],
  "connections": {
    "Split Out1": {
      "main": [
        [
          {
            "node": "cleanup",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "cleanup": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Split Out2": {
      "main": [
        [
          {
            "node": "cleanup1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "cleanup1": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "Choose The best image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Choose The best image",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Choose The best image",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "splitKeywords": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "search image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If_enable_search_google_drive": {
      "main": [
        [
          {
            "node": "splitKeywords",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "search image": {
      "main": [
        [
          {
            "node": "Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "cleanup2": {
      "main": [
        [
          {
            "node": "setRepeat",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "setRepeat": {
      "main": [
        [
          {
            "node": "Sort",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sort": {
      "main": [
        [
          {
            "node": "Limit_3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limit_3": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "trigger_search_images": {
      "main": [
        [
          {
            "node": "search on pexel",
            "type": "main",
            "index": 0
          },
          {
            "node": "search_on_freepick",
            "type": "main",
            "index": 0
          },
          {
            "node": "If_gooogle_drive_folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If_gooogle_drive_folder": {
      "main": [
        [
          {
            "node": "If_enable_search_google_drive",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "search_on_freepick": {
      "main": [
        [
          {
            "node": "Split Out1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "search on pexel": {
      "main": [
        [
          {
            "node": "Split Out2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter": {
      "main": [
        [
          {
            "node": "cleanup2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Choose The best image": {
      "main": [
        []
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "meta": null,
  "pinData": {},
  "versionId": "d059558b-8752-492c-9ecc-8cd18f8e6938",
  "activeVersionId": "d059558b-8752-492c-9ecc-8cd18f8e6938",
  "versionCounter": 14,
  "triggerCount": 0,
  "shared": [
    {
      "updatedAt": "2025-01-04T16:28:55.344Z",
      "createdAt": "2025-01-04T16:28:55.344Z",
      "role": "workflow:owner",
      "workflowId": "ITOgH8CMN7U6bMXv",
      "projectId": "Nlp7kXCVcAfb0cmG",
      "project": {
        "updatedAt": "2024-07-25T03:06:26.102Z",
        "createdAt": "2024-07-25T03:06:26.102Z",
        "id": "Nlp7kXCVcAfb0cmG",
        "name": "Bình Đặng <dangngocbinh.dnb@gmail.com>",
        "type": "personal",
        "icon": null,
        "description": null,
        "creatorId": "92f1ca82-c19e-4a7d-8458-93b65f67f4c7"
      }
    }
  ],
  "tags": [
    {
      "updatedAt": "2025-01-04T15:10:24.512Z",
      "createdAt": "2025-01-04T15:10:24.512Z",
      "id": "79hRAGEdapOrSKKd",
      "name": "canva"
    },
    {
      "updatedAt": "2024-10-04T03:03:40.628Z",
      "createdAt": "2024-10-04T03:03:40.628Z",
      "id": "MW10UcI4NI01thiG",
      "name": "share"
    },
    {
      "updatedAt": "2025-01-09T15:10:30.278Z",
      "createdAt": "2025-01-09T15:10:30.278Z",
      "id": "d1uQkjwHvetHb6dd",
      "name": "autopost2"
    }
  ],
  "activeVersion": {
    "updatedAt": "2025-11-29T04:17:05.330Z",
    "createdAt": "2025-11-29T04:17:05.330Z",
    "versionId": "d059558b-8752-492c-9ecc-8cd18f8e6938",
    "workflowId": "ITOgH8CMN7U6bMXv",
    "nodes": [
      {
        "parameters": {
          "fieldToSplitOut": "data",
          "options": {}
        },
        "type": "n8n-nodes-base.splitOut",
        "typeVersion": 1,
        "position": [
          -20,
          0
        ],
        "id": "9d38b71c-07de-421c-8d00-8ca76d5f74ae",
        "name": "Split Out1"
      },
      {
        "parameters": {
          "assignments": {
            "assignments": [
              {
                "id": "4bd1c2bd-327b-49d4-b370-d9110f54bdca",
                "name": "title",
                "value": "={{ $json.title }}",
                "type": "string"
              },
              {
                "id": "1009c406-9b3e-4193-9d2d-a1697143acc4",
                "name": "src",
                "value": "={{ $json.image.source.url }}",
                "type": "string"
              }
            ]
          },
          "options": {}
        },
        "type": "n8n-nodes-base.set",
        "typeVersion": 3.4,
        "position": [
          200,
          0
        ],
        "id": "e4473df8-3b78-4525-ba38-6de16c32fde2",
        "name": "cleanup"
      },
      {
        "parameters": {
          "fieldToSplitOut": "photos",
          "options": {}
        },
        "type": "n8n-nodes-base.splitOut",
        "typeVersion": 1,
        "position": [
          -20,
          -160
        ],
        "id": "5eb8c399-1258-4edb-83ed-33f7a426a316",
        "name": "Split Out2"
      },
      {
        "parameters": {
          "assignments": {
            "assignments": [
              {
                "id": "547a770f-66d0-4c07-8099-ec0340a4376a",
                "name": "src",
                "value": "={{ $json.src.large }}",
                "type": "string"
              },
              {
                "id": "0917edb1-37c5-42b6-aca7-094e1a62791f",
                "name": "title",
                "value": "={{ $json.alt }}",
                "type": "string"
              }
            ]
          },
          "options": {}
        },
        "type": "n8n-nodes-base.set",
        "typeVersion": 3.4,
        "position": [
          220,
          -160
        ],
        "id": "e657d412-d230-4626-a307-29a6b7cba04c",
        "name": "cleanup1"
      },
      {
        "parameters": {
          "numberInputs": 3
        },
        "type": "n8n-nodes-base.merge",
        "typeVersion": 3,
        "position": [
          1300,
          120
        ],
        "id": "989ac5ac-8c4d-4b11-b1d7-2cf5f25dd8cd",
        "name": "Merge"
      },
      {
        "parameters": {
          "aggregate": "aggregateAllItemData",
          "options": {}
        },
        "type": "n8n-nodes-base.aggregate",
        "typeVersion": 1,
        "position": [
          1560,
          120
        ],
        "id": "4b3dc39f-3ea5-426f-b1cb-788dffd33f4a",
        "name": "Aggregate"
      },
      {
        "parameters": {
          "jsonSchemaExample": "{\n\t\"title\": \"title\",\n\t\"src\": \"http://link.png\"\n}"
        },
        "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
        "typeVersion": 1.2,
        "position": [
          2100,
          280
        ],
        "id": "dbe7ae68-3825-4c9c-9ad1-25ae17b5f9b7",
        "name": "Structured Output Parser"
      },
      {
        "parameters": {
          "options": {}
        },
        "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
        "typeVersion": 1,
        "position": [
          1780,
          300
        ],
        "id": "6932244c-d763-4267-8b96-316a3db1e2b7",
        "name": "OpenAI Chat Model",
        "credentials": {
          "openAiApi": {
            "id": "hY3IQYAWuJo2IGnB",
            "name": "OpenAi binh"
          }
        }
      },
      {
        "parameters": {
          "assignments": {
            "assignments": [
              {
                "id": "79d33a28-a062-4c92-abcc-ca4c9cf324ac",
                "name": "keyword",
                "value": "={{ $json.keyword.trim().split(\" \") }}",
                "type": "array"
              }
            ]
          },
          "options": {}
        },
        "type": "n8n-nodes-base.set",
        "typeVersion": 3.4,
        "position": [
          0,
          320
        ],
        "id": "34e71061-7b6f-4220-ba50-1d056cbe6441",
        "name": "splitKeywords"
      },
      {
        "parameters": {
          "fieldToSplitOut": "keyword",
          "options": {}
        },
        "type": "n8n-nodes-base.splitOut",
        "typeVersion": 1,
        "position": [
          220,
          320
        ],
        "id": "a118caed-f6f8-40f2-82d4-6993c0fd4c1e",
        "name": "Split Out"
      },
      {
        "parameters": {
          "resource": "fileFolder",
          "queryString": "={{ $json.keyword }}",
          "returnAll": true,
          "filter": {
            "folderId": {
              "__rl": true,
              "value": "={{ $('trigger_search_images').item.json.configs[\"google-drive-photo-folder-url\"] }}",
              "mode": "url"
            },
            "whatToSearch": "files"
          },
          "options": {}
        },
        "type": "n8n-nodes-base.googleDrive",
        "typeVersion": 3,
        "position": [
          460,
          320
        ],
        "id": "06de8382-c50b-4805-830f-8cc5ca42f39f",
        "name": "search image",
        "retryOnFail": true,
        "waitBetweenTries": 3000,
        "credentials": {
          "googleDriveOAuth2Api": {
            "id": "UpcTHbah2DN5nDu8",
            "name": "Google Drive account Mecode"
          }
        }
      },
      {
        "parameters": {
          "conditions": {
            "options": {
              "caseSensitive": true,
              "leftValue": "",
              "typeValidation": "strict",
              "version": 2
            },
            "conditions": [
              {
                "id": "965fea22-1894-4dcd-9cb5-2c661ab8884b",
                "leftValue": "={{ $json.configs[\"google-drive-photo-folder-url\"] }}",
                "rightValue": "",
                "operator": {
                  "type": "string",
                  "operation": "notEmpty",
                  "singleValue": true
                }
              }
            ],
            "combinator": "and"
          },
          "options": {}
        },
        "type": "n8n-nodes-base.if",
        "typeVersion": 2.2,
        "position": [
          -200,
          340
        ],
        "id": "8ebe3734-ec1a-42a8-97b3-094d8aa22021",
        "name": "If_enable_search_google_drive"
      },
      {
        "parameters": {
          "assignments": {
            "assignments": [
              {
                "id": "4bd1c2bd-327b-49d4-b370-d9110f54bdca",
                "name": "title",
                "value": "={{ $json.name.replaceAll(/\\.(png|jpg|gif|jpeg|svg|webp)/g,\"\").trim().replace(\"-\", \" \").replaceAll(\"-\",\" \") }}",
                "type": "string"
              },
              {
                "id": "1009c406-9b3e-4193-9d2d-a1697143acc4",
                "name": "src",
                "value": "=https://{{$('trigger_search_images').item.json.configs.n8n_domain}}/webhook/autopost2-google-drive-get-img.jpg?id={{ $json.id }}&type.jpg",
                "type": "string"
              },
              {
                "id": "09ea779c-6542-446a-a48e-dffa844bdf7b",
                "name": "googledrive",
                "value": true,
                "type": "boolean"
              }
            ]
          },
          "options": {}
        },
        "type": "n8n-nodes-base.set",
        "typeVersion": 3.4,
        "position": [
          980,
          320
        ],
        "id": "5a7b033b-6504-4e08-be93-2cb9ab30342c",
        "name": "cleanup2"
      },
      {
        "parameters": {
          "sortFieldsUi": {
            "sortField": [
              {
                "fieldName": "repeat",
                "order": "descending"
              }
            ]
          },
          "options": {}
        },
        "type": "n8n-nodes-base.sort",
        "typeVersion": 1,
        "position": [
          780,
          540
        ],
        "id": "1c1f6408-a789-46bc-8002-f8393f7713b4",
        "name": "Sort"
      },
      {
        "parameters": {
          "assignments": {
            "assignments": [
              {
                "id": "de7c873a-b254-4c13-b486-8014080d076a",
                "name": "repeat",
                "value": "={{ $json.title.toLowerCase().split(\" \").filter(key => $('trigger_search_images').item.json.keyword.toLowerCase().includes(key)).length }}",
                "type": "string"
              }
            ]
          },
          "includeOtherFields": true,
          "options": {}
        },
        "type": "n8n-nodes-base.set",
        "typeVersion": 3.4,
        "position": [
          380,
          540
        ],
        "id": "413013bf-460c-46e5-b739-f9db70a4410c",
        "name": "setRepeat"
      },
      {
        "parameters": {
          "maxItems": 3
        },
        "type": "n8n-nodes-base.limit",
        "typeVersion": 1,
        "position": [
          980,
          540
        ],
        "id": "3ac289d7-c8d4-4758-b239-6f7146419a7c",
        "name": "Limit_3"
      },
      {
        "parameters": {
          "workflowInputs": {
            "values": [
              {
                "name": "alt"
              },
              {
                "name": "title"
              },
              {
                "name": "keyword"
              },
              {
                "name": "require"
              },
              {
                "name": "configs",
                "type": "object"
              }
            ]
          }
        },
        "type": "n8n-nodes-base.executeWorkflowTrigger",
        "typeVersion": 1.1,
        "position": [
          -820,
          80
        ],
        "id": "ec5069ae-bc28-46ad-907a-e92b422bd806",
        "name": "trigger_search_images"
      },
      {
        "parameters": {
          "conditions": {
            "options": {
              "caseSensitive": true,
              "leftValue": "",
              "typeValidation": "strict",
              "version": 2
            },
            "conditions": [
              {
                "id": "33033fc3-4db3-4fcf-aead-e97d89c84644",
                "leftValue": "={{ $json.configs['google-drive-photo-folder-url'] }}",
                "rightValue": "",
                "operator": {
                  "type": "string",
                  "operation": "notEmpty",
                  "singleValue": true
                }
              }
            ],
            "combinator": "and"
          },
          "options": {}
        },
        "type": "n8n-nodes-base.if",
        "typeVersion": 2.2,
        "position": [
          -580,
          140
        ],
        "id": "3c378d2f-2612-431f-a35a-7cf5b2879de4",
        "name": "If_gooogle_drive_folder"
      },
      {
        "parameters": {
          "url": "https://api.freepik.com/v1/resources",
          "sendQuery": true,
          "queryParameters": {
            "parameters": [
              {
                "name": "term",
                "value": "={{ $json.keyword }}"
              },
              {
                "name": "limit",
                "value": "5"
              },
              {
                "name": "filters",
                "value": "={{ \n\n{\n  license: {\n     freemium: 1\n  }\n}\n}}"
              }
            ]
          },
          "sendHeaders": true,
          "headerParameters": {
            "parameters": [
              {
                "name": "x-freepik-api-key",
                "value": "={{ $json.configs.freepik_api_key }}"
              }
            ]
          },
          "options": {}
        },
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4.2,
        "position": [
          -220,
          0
        ],
        "id": "927c9c2b-0571-44ab-85e9-17f3420fa7c4",
        "name": "search_on_freepick",
        "retryOnFail": true,
        "waitBetweenTries": 3000
      },
      {
        "parameters": {
          "url": "https://api.pexels.com/v1/search",
          "sendQuery": true,
          "queryParameters": {
            "parameters": [
              {
                "name": "query",
                "value": "={{ $json.keyword }}"
              },
              {
                "name": "per_page",
                "value": "5"
              },
              {
                "name": "page",
                "value": "1"
              }
            ]
          },
          "sendHeaders": true,
          "headerParameters": {
            "parameters": [
              {
                "name": "Authorization",
                "value": "={{ $json.configs.pexels_api_key }}"
              }
            ]
          },
          "options": {
            "redirect": {
              "redirect": {}
            }
          }
        },
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4.2,
        "position": [
          -220,
          -160
        ],
        "id": "94d508c0-2e06-4abe-bb4f-ac550271c9b8",
        "name": "search on pexel",
        "retryOnFail": true,
        "waitBetweenTries": 3000
      },
      {
        "parameters": {
          "conditions": {
            "options": {
              "caseSensitive": true,
              "leftValue": "",
              "typeValidation": "strict",
              "version": 2
            },
            "conditions": [
              {
                "id": "515a3cc2-1d82-477e-846a-cc3f7bee6167",
                "leftValue": "={{ $json.name }}",
                "rightValue": ".png",
                "operator": {
                  "type": "string",
                  "operation": "endsWith"
                }
              },
              {
                "id": "6d4a900c-5dda-45c5-a9aa-7d67b96123d5",
                "leftValue": "={{ $json.name }}",
                "rightValue": ".jpg",
                "operator": {
                  "type": "string",
                  "operation": "endsWith"
                }
              },
              {
                "id": "8111be19-fde4-41e3-8dde-f02d31ca78b4",
                "leftValue": "={{ $json.name }}",
                "rightValue": ".jpeg",
                "operator": {
                  "type": "string",
                  "operation": "endsWith"
                }
              },
              {
                "id": "dea365db-a02c-4807-a6d9-b3fd7039d9ff",
                "leftValue": "={{ $json.name }}",
                "rightValue": ".gif",
                "operator": {
                  "type": "string",
                  "operation": "endsWith"
                }
              },
              {
                "id": "c6507107-ce28-47be-afae-ba6a17167a08",
                "leftValue": "={{ $json.name }}",
                "rightValue": ".svg",
                "operator": {
                  "type": "string",
                  "operation": "endsWith"
                }
              }
            ],
            "combinator": "or"
          },
          "options": {}
        },
        "type": "n8n-nodes-base.filter",
        "typeVersion": 2.2,
        "position": [
          680,
          320
        ],
        "id": "189427a8-7fa1-4e01-8bb7-785b5fee8d4c",
        "name": "Filter"
      },
      {
        "parameters": {
          "promptType": "define",
          "text": "=Chọn và trả về một item hình theo tiêu chí:  {{ $('trigger_search_images').item.json.require }}\n\n- ưu tiên hình từ google drive vì đó là hình chính chủ của tôi\n\ntừ items hình sau:\n{{ $json.data.toJsonString() }}\nnếu không có kết quả nào phù hợp hãy chọn ngẫu nhiên một item",
          "hasOutputParser": true,
          "options": {}
        },
        "type": "@n8n/n8n-nodes-langchain.agent",
        "typeVersion": 1.7,
        "position": [
          1820,
          120
        ],
        "id": "6a21e22d-7f02-4572-b55e-c5efcfa148ac",
        "name": "Choose The best image",
        "retryOnFail": true,
        "waitBetweenTries": 5000
      }
    ],
    "connections": {
      "Split Out1": {
        "main": [
          [
            {
              "node": "cleanup",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "cleanup": {
        "main": [
          [
            {
              "node": "Merge",
              "type": "main",
              "index": 1
            }
          ]
        ]
      },
      "Split Out2": {
        "main": [
          [
            {
              "node": "cleanup1",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "cleanup1": {
        "main": [
          [
            {
              "node": "Merge",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Merge": {
        "main": [
          [
            {
              "node": "Aggregate",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Aggregate": {
        "main": [
          [
            {
              "node": "Choose The best image",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Structured Output Parser": {
        "ai_outputParser": [
          [
            {
              "node": "Choose The best image",
              "type": "ai_outputParser",
              "index": 0
            }
          ]
        ]
      },
      "OpenAI Chat Model": {
        "ai_languageModel": [
          [
            {
              "node": "Choose The best image",
              "type": "ai_languageModel",
              "index": 0
            }
          ]
        ]
      },
      "splitKeywords": {
        "main": [
          [
            {
              "node": "Split Out",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Split Out": {
        "main": [
          [
            {
              "node": "search image",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "If_enable_search_google_drive": {
        "main": [
          [
            {
              "node": "splitKeywords",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "search image": {
        "main": [
          [
            {
              "node": "Filter",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "cleanup2": {
        "main": [
          [
            {
              "node": "setRepeat",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "setRepeat": {
        "main": [
          [
            {
              "node": "Sort",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Sort": {
        "main": [
          [
            {
              "node": "Limit_3",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Limit_3": {
        "main": [
          [
            {
              "node": "Merge",
              "type": "main",
              "index": 2
            }
          ]
        ]
      },
      "trigger_search_images": {
        "main": [
          [
            {
              "node": "search on pexel",
              "type": "main",
              "index": 0
            },
            {
              "node": "search_on_freepick",
              "type": "main",
              "index": 0
            },
            {
              "node": "If_gooogle_drive_folder",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "If_gooogle_drive_folder": {
        "main": [
          [
            {
              "node": "If_enable_search_google_drive",
              "type": "main",
              "index": 0
            }
          ],
          [
            {
              "node": "Merge",
              "type": "main",
              "index": 2
            }
          ]
        ]
      },
      "search_on_freepick": {
        "main": [
          [
            {
              "node": "Split Out1",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "search on pexel": {
        "main": [
          [
            {
              "node": "Split Out2",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Filter": {
        "main": [
          [
            {
              "node": "cleanup2",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Choose The best image": {
        "main": [
          []
        ]
      }
    },
    "authors": "system migration",
    "name": null,
    "description": null,
    "autosaved": false,
    "workflowPublishHistory": [
      {
        "createdAt": "2025-03-21T08:34:22.000Z",
        "id": 26,
        "workflowId": "ITOgH8CMN7U6bMXv",
        "versionId": "d059558b-8752-492c-9ecc-8cd18f8e6938",
        "event": "activated",
        "userId": null
      }
    ]
  }
}