diff --git a/src/renderer/src/components/connections/connection-detail-modal.tsx b/src/renderer/src/components/connections/connection-detail-modal.tsx index 220ee418..af8e7f59 100644 --- a/src/renderer/src/components/connections/connection-detail-modal.tsx +++ b/src/renderer/src/components/connections/connection-detail-modal.tsx @@ -26,8 +26,7 @@ const CopyableSettingItem: React.FC<{ value: string | string[] displayName?: string prefix?: string[] - suffix?: string -}> = ({ title, value, displayName, prefix = [], suffix = '' }) => { +}> = ({ title, value, displayName, prefix = [] }) => { const getSubDomains = (domain: string): string[] => domain.split('.').length <= 2 ? [domain] @@ -35,6 +34,7 @@ const CopyableSettingItem: React.FC<{ .split('.') .map((_, i, parts) => parts.slice(i).join('.')) .slice(0, -1) + const isIPv6 = (ip: string) => ip.includes(':') const menuItems = [ { key: 'raw', text: displayName || (Array.isArray(value) ? value.join(', ') : value) }, @@ -43,8 +43,8 @@ const CopyableSettingItem: React.FC<{ .map((p, i) => value[i] ? { - key: `${p},${p === 'IP-ASN' ? value[i].split(' ')[0] : value[i]}${suffix}`, - text: `${p},${p === 'IP-ASN' ? value[i].split(' ')[0] : value[i]}${suffix}` + key: `${p},${p === 'IP-ASN' ? value[i].split(' ')[0] : value[i]}${(p === 'IP-CIDR' || p === 'SRC-IP-CIDR') ? (isIPv6(value[i]) ? '/128' : '/32') : ''}`, + text: `${p},${p === 'IP-ASN' ? value[i].split(' ')[0] : value[i]}${(p === 'IP-CIDR' || p === 'SRC-IP-CIDR') ? (isIPv6(value[i]) ? '/128' : '/32') : ''}` } : null ) @@ -55,40 +55,40 @@ const CopyableSettingItem: React.FC<{ .map((v) => p === 'DOMAIN-SUFFIX' ? getSubDomains(v).map((subV) => ({ - key: `${p},${subV}${suffix}`, - text: `${p},${subV}${suffix}` + key: `${p},${subV}`, + text: `${p},${subV}` })) : p === 'IP-ASN' || p === 'SRC-IP-ASN' ? [ { - key: `${p},${v.split(' ')[0]}${suffix}`, - text: `${p},${v.split(' ')[0]}${suffix}` + key: `${p},${v.split(' ')[0]}`, + text: `${p},${v.split(' ')[0]}` } ] : [ { - key: `${p},${v}${suffix}`, - text: `${p},${v}${suffix}` + key: `${p},${v}${(p === 'IP-CIDR' || p === 'SRC-IP-CIDR') ? (isIPv6(v) ? '/128' : '/32') : ''}`, + text: `${p},${v}${(p === 'IP-CIDR' || p === 'SRC-IP-CIDR') ? (isIPv6(v) ? '/128' : '/32') : ''}` } ] ) .flat() : p === 'DOMAIN-SUFFIX' ? getSubDomains(value).map((v) => ({ - key: `${p},${v}${suffix}`, - text: `${p},${v}${suffix}` + key: `${p},${v}`, + text: `${p},${v}` })) : p === 'IP-ASN' || p === 'SRC-IP-ASN' ? [ { - key: `${p},${value.split(' ')[0]}${suffix}`, - text: `${p},${value.split(' ')[0]}${suffix}` + key: `${p},${value.split(' ')[0]}`, + text: `${p},${value.split(' ')[0]}` } ] : [ { - key: `${p},${value}${suffix}`, - text: `${p},${value}${suffix}` + key: `${p},${value}${(p === 'IP-CIDR' || p === 'SRC-IP-CIDR') ? (isIPv6(value) ? '/128' : '/32') : ''}`, + text: `${p},${value}${(p === 'IP-CIDR' || p === 'SRC-IP-CIDR') ? (isIPv6(value) ? '/128' : '/32') : ''}` } ] )) @@ -193,7 +193,6 @@ const ConnectionDetailModal: React.FC = (props) => { title="来源IP" value={connection.metadata.sourceIP} prefix={['SRC-IP-CIDR']} - suffix="/32" /> )} {connection.metadata.sourceGeoIP && connection.metadata.sourceGeoIP.length > 0 && ( @@ -215,7 +214,6 @@ const ConnectionDetailModal: React.FC = (props) => { title="目标IP" value={connection.metadata.destinationIP} prefix={['IP-CIDR']} - suffix="/32" /> )} {connection.metadata.destinationGeoIP &&