fix(10-07): add fuzzy matching to logs and fix chatId reference
- Send Logs Response now uses Prepare Text Logs Input for chatId - Container logs sub-workflow uses .includes() for fuzzy matching - Multiple match handling added with helpful error message
This commit is contained in:
@@ -95,7 +95,7 @@
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"jsCode": "// Find container by name\nconst dockerOutput = $input.item.json.stdout;\nconst data = $('Check Container ID').item.json;\nconst containerName = data.containerName.toLowerCase();\n\n// Parse Docker response\nlet containers;\ntry {\n containers = JSON.parse(dockerOutput);\n} catch (e) {\n throw new Error('Failed to parse Docker response');\n}\n\n// Normalize name function\nfunction normalizeName(name) {\n return name\n .replace(/^\\//, '')\n .replace(/^(linuxserver[-_]|binhex[-_])/i, '')\n .toLowerCase();\n}\n\n// Find exact match\nconst container = containers.find(c => normalizeName(c.Names[0]) === containerName);\n\nif (!container) {\n throw new Error(`Container \"${containerName}\" not found`);\n}\n\nreturn {\n json: {\n ...data,\n containerId: container.Id,\n containerName: normalizeName(container.Names[0])\n }\n};"
|
||||
"jsCode": "// Find container by name (supports fuzzy matching)\nconst dockerOutput = $input.item.json.stdout;\nconst data = $('Check Container ID').item.json;\nconst containerName = data.containerName.toLowerCase();\n\n// Parse Docker response\nlet containers;\ntry {\n containers = JSON.parse(dockerOutput);\n} catch (e) {\n throw new Error('Failed to parse Docker response');\n}\n\n// Normalize name function\nfunction normalizeName(name) {\n return name\n .replace(/^\\//, '')\n .replace(/^(linuxserver[-_]|binhex[-_])/i, '')\n .toLowerCase();\n}\n\n// Find containers that match (fuzzy - includes search term)\nconst matches = containers.filter(c => normalizeName(c.Names[0]).includes(containerName));\n\nif (matches.length === 0) {\n throw new Error(`Container \"${containerName}\" not found`);\n}\n\nif (matches.length > 1) {\n const matchNames = matches.map(c => normalizeName(c.Names[0])).join(', ');\n throw new Error(`Multiple containers match \"${containerName}\": ${matchNames}`);\n}\n\nconst container = matches[0];\n\nreturn {\n json: {\n ...data,\n containerId: container.Id,\n containerName: normalizeName(container.Names[0])\n }\n};"
|
||||
},
|
||||
"id": "52dd705b-dd3b-4fdc-8484-276845857ad0",
|
||||
"name": "Find Container",
|
||||
|
||||
Reference in New Issue
Block a user