mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
fix process-name/ipcidr copy
This commit is contained in:
parent
22c35b606e
commit
56139a5e9f
@ -26,8 +26,7 @@ const CopyableSettingItem: React.FC<{
|
|||||||
value: string | string[]
|
value: string | string[]
|
||||||
displayName?: string
|
displayName?: string
|
||||||
prefix?: string[]
|
prefix?: string[]
|
||||||
suffix?: string
|
}> = ({ title, value, displayName, prefix = [] }) => {
|
||||||
}> = ({ title, value, displayName, prefix = [], suffix = '' }) => {
|
|
||||||
const getSubDomains = (domain: string): string[] =>
|
const getSubDomains = (domain: string): string[] =>
|
||||||
domain.split('.').length <= 2
|
domain.split('.').length <= 2
|
||||||
? [domain]
|
? [domain]
|
||||||
@ -35,63 +34,57 @@ const CopyableSettingItem: React.FC<{
|
|||||||
.split('.')
|
.split('.')
|
||||||
.map((_, i, parts) => parts.slice(i).join('.'))
|
.map((_, i, parts) => parts.slice(i).join('.'))
|
||||||
.slice(0, -1)
|
.slice(0, -1)
|
||||||
|
const isIPv6 = (ip: string) => ip.includes(':')
|
||||||
|
|
||||||
const menuItems = [
|
const menuItems = [
|
||||||
{ key: 'raw', text: displayName || (Array.isArray(value) ? value.join(', ') : value) },
|
{ key: 'raw', text: displayName || (Array.isArray(value) ? value.join(', ') : value) },
|
||||||
...(Array.isArray(value) && value.length === prefix.length
|
...(Array.isArray(value)
|
||||||
? prefix
|
? value.map((v, i) => {
|
||||||
.map((p, i) =>
|
const p = prefix[i]
|
||||||
value[i]
|
if (!p || !v) return null
|
||||||
? {
|
|
||||||
key: `${p},${p === 'IP-ASN' ? value[i].split(' ')[0] : value[i]}${suffix}`,
|
if (p === 'DOMAIN-SUFFIX') {
|
||||||
text: `${p},${p === 'IP-ASN' ? value[i].split(' ')[0] : value[i]}${suffix}`
|
return getSubDomains(v).map((subV) => ({
|
||||||
}
|
key: `${p},${subV}`,
|
||||||
: null
|
text: `${p},${subV}`
|
||||||
)
|
|
||||||
.filter(Boolean)
|
|
||||||
: prefix.flatMap((p) =>
|
|
||||||
Array.isArray(value)
|
|
||||||
? value
|
|
||||||
.map((v) =>
|
|
||||||
p === 'DOMAIN-SUFFIX'
|
|
||||||
? getSubDomains(v).map((subV) => ({
|
|
||||||
key: `${p},${subV}${suffix}`,
|
|
||||||
text: `${p},${subV}${suffix}`
|
|
||||||
}))
|
}))
|
||||||
: p === 'IP-ASN' || p === 'SRC-IP-ASN'
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
key: `${p},${v.split(' ')[0]}${suffix}`,
|
|
||||||
text: `${p},${v.split(' ')[0]}${suffix}`
|
|
||||||
}
|
}
|
||||||
]
|
|
||||||
: [
|
if (p === 'IP-ASN' || p === 'SRC-IP-ASN') {
|
||||||
{
|
return {
|
||||||
|
key: `${p},${v.split(' ')[0]}`,
|
||||||
|
text: `${p},${v.split(' ')[0]}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const suffix = (p === 'IP-CIDR' || p === 'SRC-IP-CIDR') ? (isIPv6(v) ? '/128' : '/32') : ''
|
||||||
|
return {
|
||||||
key: `${p},${v}${suffix}`,
|
key: `${p},${v}${suffix}`,
|
||||||
text: `${p},${v}${suffix}`
|
text: `${p},${v}${suffix}`
|
||||||
}
|
}
|
||||||
]
|
}).filter(Boolean).flat()
|
||||||
)
|
: prefix.map(p => {
|
||||||
.flat()
|
const v = value as string
|
||||||
: p === 'DOMAIN-SUFFIX'
|
if (p === 'DOMAIN-SUFFIX') {
|
||||||
? getSubDomains(value).map((v) => ({
|
return getSubDomains(v).map((subV) => ({
|
||||||
|
key: `${p},${subV}`,
|
||||||
|
text: `${p},${subV}`
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p === 'IP-ASN' || p === 'SRC-IP-ASN') {
|
||||||
|
return {
|
||||||
|
key: `${p},${v.split(' ')[0]}`,
|
||||||
|
text: `${p},${v.split(' ')[0]}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const suffix = (p === 'IP-CIDR' || p === 'SRC-IP-CIDR') ? (isIPv6(v) ? '/128' : '/32') : ''
|
||||||
|
return {
|
||||||
key: `${p},${v}${suffix}`,
|
key: `${p},${v}${suffix}`,
|
||||||
text: `${p},${v}${suffix}`
|
text: `${p},${v}${suffix}`
|
||||||
}))
|
|
||||||
: p === 'IP-ASN' || p === 'SRC-IP-ASN'
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
key: `${p},${value.split(' ')[0]}${suffix}`,
|
|
||||||
text: `${p},${value.split(' ')[0]}${suffix}`
|
|
||||||
}
|
}
|
||||||
]
|
}).flat())
|
||||||
: [
|
|
||||||
{
|
|
||||||
key: `${p},${value}${suffix}`,
|
|
||||||
text: `${p},${value}${suffix}`
|
|
||||||
}
|
|
||||||
]
|
|
||||||
))
|
|
||||||
]
|
]
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -175,10 +168,10 @@ const ConnectionDetailModal: React.FC<Props> = (props) => {
|
|||||||
title="进程名"
|
title="进程名"
|
||||||
value={[
|
value={[
|
||||||
connection.metadata.process,
|
connection.metadata.process,
|
||||||
connection.metadata.uid ? connection.metadata.uid.toString() : ''
|
...(connection.metadata.uid ? [connection.metadata.uid.toString()] : [])
|
||||||
]}
|
]}
|
||||||
displayName={`${connection.metadata.process}${connection.metadata.uid ? `(${connection.metadata.uid})` : ''}`}
|
displayName={`${connection.metadata.process}${connection.metadata.uid ? `(${connection.metadata.uid})` : ''}`}
|
||||||
prefix={['PROCESS-NAME', 'UID']}
|
prefix={['PROCESS-NAME', ...(connection.metadata.uid ? ['UID'] : [])]}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{connection.metadata.processPath && (
|
{connection.metadata.processPath && (
|
||||||
@ -193,7 +186,6 @@ const ConnectionDetailModal: React.FC<Props> = (props) => {
|
|||||||
title="来源IP"
|
title="来源IP"
|
||||||
value={connection.metadata.sourceIP}
|
value={connection.metadata.sourceIP}
|
||||||
prefix={['SRC-IP-CIDR']}
|
prefix={['SRC-IP-CIDR']}
|
||||||
suffix="/32"
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{connection.metadata.sourceGeoIP && connection.metadata.sourceGeoIP.length > 0 && (
|
{connection.metadata.sourceGeoIP && connection.metadata.sourceGeoIP.length > 0 && (
|
||||||
@ -215,7 +207,6 @@ const ConnectionDetailModal: React.FC<Props> = (props) => {
|
|||||||
title="目标IP"
|
title="目标IP"
|
||||||
value={connection.metadata.destinationIP}
|
value={connection.metadata.destinationIP}
|
||||||
prefix={['IP-CIDR']}
|
prefix={['IP-CIDR']}
|
||||||
suffix="/32"
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{connection.metadata.destinationGeoIP &&
|
{connection.metadata.destinationGeoIP &&
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user