From 3c7f70175fdddd08f732909504e0cd443f322f55 Mon Sep 17 00:00:00 2001 From: MarekWo Date: Sat, 28 Mar 2026 14:28:40 +0100 Subject: [PATCH] fix(dm): handle FLOOD delivery and old DIRECT path gracefully Add hex validation to formatDmRoute to avoid garbling old "DIRECT" values. When no hex route available (FLOOD delivery), fall back to delivery_route from ACK (e.g. show "FLOOD" stripped of PATH_ prefix). Ensures delivery meta always shows something useful. Co-Authored-By: Claude Opus 4.6 --- app/static/js/dm.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/app/static/js/dm.js b/app/static/js/dm.js index 448b959..209e4ae 100644 --- a/app/static/js/dm.js +++ b/app/static/js/dm.js @@ -162,7 +162,8 @@ function connectChatSocket() { // Build delivery meta text const parts = []; if (data.attempt && data.max_attempts) parts.push(`Attempt ${data.attempt}/${data.max_attempts}`); - if (data.path) parts.push(`Route: ${formatDmRoute(data.path)}`); + const hexRoute = formatDmRoute(data.path); + if (hexRoute) parts.push(`Route: ${hexRoute}`); if (parts.length > 0) { let metaEl = msgDiv.querySelector('.dm-delivery-meta'); if (!metaEl) { @@ -1154,7 +1155,9 @@ function displayMessages(messages) { if (msg.delivery_attempt && msg.delivery_max_attempts) { title += ` (${msg.delivery_attempt}/${msg.delivery_max_attempts})`; } - if (msg.delivery_path) title += `, Route: ${formatDmRoute(msg.delivery_path)}`; + const route = formatDmRoute(msg.delivery_path); + if (route) title += `, Route: ${route}`; + else if (msg.delivery_route) title += `, ${msg.delivery_route.replace('PATH_', '')}`; if (msg.delivery_snr !== null && msg.delivery_snr !== undefined) { title += `, SNR: ${msg.delivery_snr.toFixed(1)} dB`; } @@ -1191,8 +1194,14 @@ function displayMessages(messages) { parts.push(`Attempt ${msg.delivery_attempt}/${msg.delivery_max_attempts}`); } // Show route only for delivered messages (not failed) - if (msg.status === 'delivered' && msg.delivery_path) { - parts.push(`Route: ${formatDmRoute(msg.delivery_path)}`); + if (msg.status === 'delivered') { + const hexRoute = formatDmRoute(msg.delivery_path); + if (hexRoute) { + parts.push(`Route: ${hexRoute}`); + } else if (msg.delivery_route) { + // Fallback: show ACK route type (e.g. FLOOD, direct) + parts.push(msg.delivery_route.replace('PATH_', '')); + } } deliveryMeta = `
${parts.join(', ')}
`; } @@ -1365,10 +1374,10 @@ function resendMessage(content) { /** * Format a hex path as route string (e.g. "5e34e761" → "5e→34→e7→61") - * Truncates if more than 4 segments. + * Truncates if more than 4 segments. Returns '' for non-hex strings. */ function formatDmRoute(hexPath) { - if (!hexPath) return ''; + if (!hexPath || !/^[0-9a-f]+$/i.test(hexPath)) return ''; const segments = hexPath.match(/.{1,2}/g) || []; if (segments.length === 0) return ''; if (segments.length > 4) {