feat(11-02): add Update All button to container list with callback routing

- Add 'Update All :latest' button to Build Container List and Build Paginated List
- Add uall:start parser to Parse Callback Data (sets isUpdateAllStart flag)
- Add updateallstart rule to Route Callback (index 2)
- Add Answer Update All Start node with 'Checking for updates...' callback response
- Wire Route Callback [updateallstart] -> Answer Update All Start -> Get All Containers For Update All
- Fix Check Available Updates to support both text and callback origins (try/catch for Keyword Router vs Parse Callback Data)
This commit is contained in:
Lucas Berger
2026-02-08 16:22:28 -05:00
parent 339b366bcc
commit 3275e190c4
2 changed files with 69 additions and 4 deletions
+2 -2
View File
@@ -173,7 +173,7 @@
},
{
"parameters": {
"jsCode": "// Build Paginated Container List Keyboard\nconst containers = $input.all().map(item => item.json);\nconst prevData = $(\"Prepare List Request\").item.json;\nconst chatId = prevData.chatId;\nconst messageId = prevData.messageId;\nconst page = prevData.page || 0;\nconst searchTerm = prevData.searchTerm;\n\n// Function to normalize container names (strip prefixes)\nfunction normalizeName(name) {\n return name\n .replace(/^\\//, '')\n .replace(/^(linuxserver[-_]|binhex[-_])/i, '')\n .toLowerCase();\n}\n\n// If specific container requested via search term, check for exact/single match\nif (searchTerm) {\n const matches = containers.filter(c => {\n const containerName = normalizeName(c.Names[0]);\n return containerName.includes(searchTerm.toLowerCase());\n });\n \n if (matches.length === 1) {\n const container = matches[0];\n const containerName = normalizeName(container.Names[0]);\n const state = container.State;\n const status = container.Status;\n const image = container.Image;\n \n // Build action keyboard based on container state\n const keyboard = [];\n if (state === 'running') {\n keyboard.push([\n { text: '\\u23F9\\uFE0F Stop', callback_data: `action:stop:${containerName}` },\n { text: '\\u{1F504} Restart', callback_data: `action:restart:${containerName}` }\n ]);\n } else {\n keyboard.push([\n { text: '\\u25B6\\uFE0F Start', callback_data: `action:start:${containerName}` }\n ]);\n }\n keyboard.push([\n { text: '\\u{1F4CB} Logs', callback_data: `action:logs:${containerName}` },\n { text: '\\u2B06\\uFE0F Update', callback_data: `action:update:${containerName}` }\n ]);\n keyboard.push([\n { text: '\\u25C0\\uFE0F Back to List', callback_data: 'list:0' }\n ]);\n \n // Build status text\n const stateIcon = state === 'running' ? '\\u{1F7E2}' : '\\u26AA';\n let text = `${stateIcon} <b>${containerName}</b>\\n\\n`;\n text += `<b>State:</b> ${state}\\n`;\n text += `<b>Status:</b> ${status}\\n`;\n text += `<b>Image:</b> ${image}`;\n \n return [{\n json: {\n success: true,\n action: 'status_direct',\n chatId,\n messageId,\n text,\n reply_markup: { inline_keyboard: keyboard },\n container: { id: container.Id, name: containerName, state, status, image }\n }\n }];\n } else if (matches.length === 0) {\n return [{\n json: {\n success: false,\n action: 'list',\n chatId,\n messageId,\n error: `No container found matching \"${searchTerm}\"`,\n text: `No container found matching \"${searchTerm}\"`\n }\n }];\n }\n // Multiple matches - continue to show list\n}\n\nconst containersPerPage = 6;\n\n// Group by state (running first)\nconst running = containers.filter(c => c.State === 'running');\nconst stopped = containers.filter(c => c.State !== 'running');\nconst sortedContainers = [...running, ...stopped];\n\nconst totalPages = Math.ceil(sortedContainers.length / containersPerPage);\nconst start = page * containersPerPage;\nconst pageContainers = sortedContainers.slice(start, start + containersPerPage);\n\n// Build keyboard rows\nconst keyboard = [];\n\npageContainers.forEach(container => {\n const name = normalizeName(container.Names[0]);\n const stateIcon = container.State === 'running' ? '\\u{1F7E2}' : '\\u26AA'; // Green circle or white circle\n const stateText = container.State === 'running' ? 'Running' : 'Stopped';\n keyboard.push([{\n text: `${stateIcon} ${name} - ${stateText}`,\n callback_data: `select:${name}`\n }]);\n});\n\n// Add navigation row if needed\nif (totalPages > 1) {\n const navRow = [];\n if (page > 0) {\n navRow.push({ text: '\\u25C0\\uFE0F Previous', callback_data: `list:${page - 1}` });\n }\n navRow.push({ text: `${page + 1}/${totalPages}`, callback_data: 'noop' });\n if (page < totalPages - 1) {\n navRow.push({ text: 'Next \\u25B6\\uFE0F', callback_data: `list:${page + 1}` });\n }\n keyboard.push(navRow);\n}\n\n// Add Select Multiple button for batch operations\nkeyboard.push([{ text: '\\u2611\\ufe0f Select Multiple', callback_data: 'batch:mode' }]);\n\n// Build header text\nconst runningCount = running.length;\nconst totalCount = sortedContainers.length;\nlet headerText = `<b>\\u{1F5C2} Containers</b> (${runningCount}/${totalCount} running)`;\nif (totalPages > 1) {\n headerText += `\\n\\nPage ${page + 1} of ${totalPages}`;\n}\nheaderText += '\\n\\nTap a container to manage it:';\n\nreturn [{\n json: {\n success: true,\n action: 'list',\n chatId,\n messageId,\n text: headerText,\n reply_markup: { inline_keyboard: keyboard },\n totalContainers: totalCount,\n currentPage: page,\n totalPages\n }\n}];"
"jsCode": "// Build Paginated Container List Keyboard\nconst containers = $input.all().map(item => item.json);\nconst prevData = $(\"Prepare List Request\").item.json;\nconst chatId = prevData.chatId;\nconst messageId = prevData.messageId;\nconst page = prevData.page || 0;\nconst searchTerm = prevData.searchTerm;\n\n// Function to normalize container names (strip prefixes)\nfunction normalizeName(name) {\n return name\n .replace(/^\\//, '')\n .replace(/^(linuxserver[-_]|binhex[-_])/i, '')\n .toLowerCase();\n}\n\n// If specific container requested via search term, check for exact/single match\nif (searchTerm) {\n const matches = containers.filter(c => {\n const containerName = normalizeName(c.Names[0]);\n return containerName.includes(searchTerm.toLowerCase());\n });\n \n if (matches.length === 1) {\n const container = matches[0];\n const containerName = normalizeName(container.Names[0]);\n const state = container.State;\n const status = container.Status;\n const image = container.Image;\n \n // Build action keyboard based on container state\n const keyboard = [];\n if (state === 'running') {\n keyboard.push([\n { text: '\\u23F9\\uFE0F Stop', callback_data: `action:stop:${containerName}` },\n { text: '\\u{1F504} Restart', callback_data: `action:restart:${containerName}` }\n ]);\n } else {\n keyboard.push([\n { text: '\\u25B6\\uFE0F Start', callback_data: `action:start:${containerName}` }\n ]);\n }\n keyboard.push([\n { text: '\\u{1F4CB} Logs', callback_data: `action:logs:${containerName}` },\n { text: '\\u2B06\\uFE0F Update', callback_data: `action:update:${containerName}` }\n ]);\n keyboard.push([\n { text: '\\u25C0\\uFE0F Back to List', callback_data: 'list:0' }\n ]);\n \n // Build status text\n const stateIcon = state === 'running' ? '\\u{1F7E2}' : '\\u26AA';\n let text = `${stateIcon} <b>${containerName}</b>\\n\\n`;\n text += `<b>State:</b> ${state}\\n`;\n text += `<b>Status:</b> ${status}\\n`;\n text += `<b>Image:</b> ${image}`;\n \n return [{\n json: {\n success: true,\n action: 'status_direct',\n chatId,\n messageId,\n text,\n reply_markup: { inline_keyboard: keyboard },\n container: { id: container.Id, name: containerName, state, status, image }\n }\n }];\n } else if (matches.length === 0) {\n return [{\n json: {\n success: false,\n action: 'list',\n chatId,\n messageId,\n error: `No container found matching \"${searchTerm}\"`,\n text: `No container found matching \"${searchTerm}\"`\n }\n }];\n }\n // Multiple matches - continue to show list\n}\n\nconst containersPerPage = 6;\n\n// Group by state (running first)\nconst running = containers.filter(c => c.State === 'running');\nconst stopped = containers.filter(c => c.State !== 'running');\nconst sortedContainers = [...running, ...stopped];\n\nconst totalPages = Math.ceil(sortedContainers.length / containersPerPage);\nconst start = page * containersPerPage;\nconst pageContainers = sortedContainers.slice(start, start + containersPerPage);\n\n// Build keyboard rows\nconst keyboard = [];\n\npageContainers.forEach(container => {\n const name = normalizeName(container.Names[0]);\n const stateIcon = container.State === 'running' ? '\\u{1F7E2}' : '\\u26AA'; // Green circle or white circle\n const stateText = container.State === 'running' ? 'Running' : 'Stopped';\n keyboard.push([{\n text: `${stateIcon} ${name} - ${stateText}`,\n callback_data: `select:${name}`\n }]);\n});\n\n// Add navigation row if needed\nif (totalPages > 1) {\n const navRow = [];\n if (page > 0) {\n navRow.push({ text: '\\u25C0\\uFE0F Previous', callback_data: `list:${page - 1}` });\n }\n navRow.push({ text: `${page + 1}/${totalPages}`, callback_data: 'noop' });\n if (page < totalPages - 1) {\n navRow.push({ text: 'Next \\u25B6\\uFE0F', callback_data: `list:${page + 1}` });\n }\n keyboard.push(navRow);\n}\n\n// Add Update All button\nkeyboard.push([{\n text: '\\u{1F504} Update All :latest',\n callback_data: 'uall:start'\n}]);\n\n// Add Select Multiple button for batch operations\nkeyboard.push([{ text: '\\u2611\\ufe0f Select Multiple', callback_data: 'batch:mode' }]);\n\n// Build header text\nconst runningCount = running.length;\nconst totalCount = sortedContainers.length;\nlet headerText = `<b>\\u{1F5C2} Containers</b> (${runningCount}/${totalCount} running)`;\nif (totalPages > 1) {\n headerText += `\\n\\nPage ${page + 1} of ${totalPages}`;\n}\nheaderText += '\\n\\nTap a container to manage it:';\n\nreturn [{\n json: {\n success: true,\n action: 'list',\n chatId,\n messageId,\n text: headerText,\n reply_markup: { inline_keyboard: keyboard },\n totalContainers: totalCount,\n currentPage: page,\n totalPages\n }\n}];"
},
"id": "status-build-list",
"name": "Build Container List",
@@ -255,7 +255,7 @@
},
{
"parameters": {
"jsCode": "// Build Paginated Container List Keyboard for pagination callbacks\nconst containers = $input.all().map(item => item.json);\nconst prevData = $(\"Prepare Paginate Request\").item.json;\nconst chatId = prevData.chatId;\nconst messageId = prevData.messageId;\nconst page = prevData.page || 0;\n\n// Function to normalize container names\nfunction normalizeName(name) {\n return name\n .replace(/^\\//, '')\n .replace(/^(linuxserver[-_]|binhex[-_])/i, '')\n .toLowerCase();\n}\n\nconst containersPerPage = 6;\n\n// Group by state (running first)\nconst running = containers.filter(c => c.State === 'running');\nconst stopped = containers.filter(c => c.State !== 'running');\nconst sortedContainers = [...running, ...stopped];\n\nconst totalPages = Math.ceil(sortedContainers.length / containersPerPage);\nconst start = page * containersPerPage;\nconst pageContainers = sortedContainers.slice(start, start + containersPerPage);\n\n// Build keyboard rows\nconst keyboard = [];\n\npageContainers.forEach(container => {\n const name = normalizeName(container.Names[0]);\n const stateIcon = container.State === 'running' ? '\\u{1F7E2}' : '\\u26AA';\n const stateText = container.State === 'running' ? 'Running' : 'Stopped';\n keyboard.push([{\n text: `${stateIcon} ${name} - ${stateText}`,\n callback_data: `select:${name}`\n }]);\n});\n\n// Add navigation row if needed\nif (totalPages > 1) {\n const navRow = [];\n if (page > 0) {\n navRow.push({ text: '\\u25C0\\uFE0F Previous', callback_data: `list:${page - 1}` });\n }\n navRow.push({ text: `${page + 1}/${totalPages}`, callback_data: 'noop' });\n if (page < totalPages - 1) {\n navRow.push({ text: 'Next \\u25B6\\uFE0F', callback_data: `list:${page + 1}` });\n }\n keyboard.push(navRow);\n}\n\n// Add Select Multiple button for batch operations\nkeyboard.push([{ text: '\\u2611\\ufe0f Select Multiple', callback_data: 'batch:mode' }]);\n\n// Build header text\nconst runningCount = running.length;\nconst totalCount = sortedContainers.length;\nlet headerText = `<b>\\u{1F5C2} Containers</b> (${runningCount}/${totalCount} running)`;\nif (totalPages > 1) {\n headerText += `\\n\\nPage ${page + 1} of ${totalPages}`;\n}\nheaderText += '\\n\\nTap a container to manage it:';\n\nreturn [{\n json: {\n success: true,\n action: 'paginate',\n chatId,\n messageId,\n text: headerText,\n reply_markup: { inline_keyboard: keyboard },\n totalContainers: totalCount,\n currentPage: page,\n totalPages\n }\n}];"
"jsCode": "// Build Paginated Container List Keyboard for pagination callbacks\nconst containers = $input.all().map(item => item.json);\nconst prevData = $(\"Prepare Paginate Request\").item.json;\nconst chatId = prevData.chatId;\nconst messageId = prevData.messageId;\nconst page = prevData.page || 0;\n\n// Function to normalize container names\nfunction normalizeName(name) {\n return name\n .replace(/^\\//, '')\n .replace(/^(linuxserver[-_]|binhex[-_])/i, '')\n .toLowerCase();\n}\n\nconst containersPerPage = 6;\n\n// Group by state (running first)\nconst running = containers.filter(c => c.State === 'running');\nconst stopped = containers.filter(c => c.State !== 'running');\nconst sortedContainers = [...running, ...stopped];\n\nconst totalPages = Math.ceil(sortedContainers.length / containersPerPage);\nconst start = page * containersPerPage;\nconst pageContainers = sortedContainers.slice(start, start + containersPerPage);\n\n// Build keyboard rows\nconst keyboard = [];\n\npageContainers.forEach(container => {\n const name = normalizeName(container.Names[0]);\n const stateIcon = container.State === 'running' ? '\\u{1F7E2}' : '\\u26AA';\n const stateText = container.State === 'running' ? 'Running' : 'Stopped';\n keyboard.push([{\n text: `${stateIcon} ${name} - ${stateText}`,\n callback_data: `select:${name}`\n }]);\n});\n\n// Add navigation row if needed\nif (totalPages > 1) {\n const navRow = [];\n if (page > 0) {\n navRow.push({ text: '\\u25C0\\uFE0F Previous', callback_data: `list:${page - 1}` });\n }\n navRow.push({ text: `${page + 1}/${totalPages}`, callback_data: 'noop' });\n if (page < totalPages - 1) {\n navRow.push({ text: 'Next \\u25B6\\uFE0F', callback_data: `list:${page + 1}` });\n }\n keyboard.push(navRow);\n}\n\n// Add Update All button\nkeyboard.push([{\n text: '\\u{1F504} Update All :latest',\n callback_data: 'uall:start'\n}]);\n\n// Add Select Multiple button for batch operations\nkeyboard.push([{ text: '\\u2611\\ufe0f Select Multiple', callback_data: 'batch:mode' }]);\n\n// Build header text\nconst runningCount = running.length;\nconst totalCount = sortedContainers.length;\nlet headerText = `<b>\\u{1F5C2} Containers</b> (${runningCount}/${totalCount} running)`;\nif (totalPages > 1) {\n headerText += `\\n\\nPage ${page + 1} of ${totalPages}`;\n}\nheaderText += '\\n\\nTap a container to manage it:';\n\nreturn [{\n json: {\n success: true,\n action: 'paginate',\n chatId,\n messageId,\n text: headerText,\n reply_markup: { inline_keyboard: keyboard },\n totalContainers: totalCount,\n currentPage: page,\n totalPages\n }\n}];"
},
"id": "status-build-paginated",
"name": "Build Paginated List",