Skip to content

Commit 14d5ff7

Browse files
committed
fix: improve ip parsing result
1 parent 3d52090 commit 14d5ff7

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

util/ip.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,21 @@ func GetDescFromIP(ip string) string {
106106
return ""
107107
}
108108

109-
res := info.Country + ", " + info.Region + ", " + info.City
110-
if info.Isp != Null {
111-
res += ", " + info.Isp
109+
parts := []string{}
110+
if info.Country != "" {
111+
parts = append(parts, info.Country)
112+
}
113+
if info.Region != "" {
114+
parts = append(parts, info.Region)
115+
}
116+
if info.City != "" {
117+
parts = append(parts, info.City)
118+
}
119+
if info.Isp != Null && info.Isp != "" {
120+
parts = append(parts, info.Isp)
112121
}
113122

114-
return res
123+
return strings.Join(parts, ", ")
115124
}
116125

117126
func GetIPInfo(clientIP string) string {

web/src/ChatListPage.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,15 +492,22 @@ class ChatListPage extends BaseListPage {
492492
return null;
493493
}
494494

495+
const ipDesc = record.clientIpDesc
496+
? record.clientIpDesc.split(",").map(s => s.trim()).filter(s => s !== "").join(", ")
497+
: "";
498+
495499
return (
496500
<a target="_blank" rel="noreferrer" href={`https://db-ip.com/${text}`}>
497501
{
498-
record.clientIpDesc === "" ? text : (
502+
ipDesc === "" && record.userAgentDesc === "" && record.userAgent === "" ? text : (
499503
<div>
500504
{text}
501-
<br />
502-
{record.clientIpDesc}
503-
<br />
505+
{ipDesc !== "" && (
506+
<>
507+
<br />
508+
{ipDesc}
509+
</>
510+
)}
504511
<br />
505512
{
506513
this.renderUserAgent(record)

0 commit comments

Comments
 (0)