Ver código fonte

feat(discovery): 支持动态HTTP端口发现与连接

服务端在发现响应中增加HTTP端口字段,客户端据此构建地址,替代硬编码端口以提升灵活性。
yangkaixiang 1 mês atrás
pai
commit
dd332033ce

+ 1 - 1
server/internal/config/config.go

@@ -6,7 +6,7 @@ import (
 	"net"
 )
 
-const ServerVersion = "20260511154000"
+const ServerVersion = "20260511180458"
 
 type Config struct {
 	HTTPHost         string

+ 1 - 0
server/internal/discovery/discovery.go

@@ -65,6 +65,7 @@ func (s *Server) Run(ctx context.Context) error {
 			ServerVersion:   device.ServerVersion,
 			MAC:             findMACByIP(s.cfg.MaintenanceIP),
 			LAN2IP:          s.cfg.MaintenanceIP,
+			HTTPPort:        s.cfg.HTTPPort,
 			AuthRequired:    true,
 		}
 		payload, _ := json.Marshal(resp)

+ 1 - 0
server/internal/model/types.go

@@ -56,6 +56,7 @@ type DiscoverResponse struct {
 	ServerVersion   string `json:"server_version"`
 	MAC             string `json:"mac"`
 	LAN2IP          string `json:"lan2_ip"`
+	HTTPPort        int    `json:"http_port"`
 	AuthRequired    bool   `json:"auth_required"`
 }
 

+ 2 - 1
windows/NetworkTool.Client/MainWindow.xaml.cs

@@ -265,7 +265,8 @@ public partial class MainWindow : Window
 
         try
         {
-            var baseAddress = $"http://{device.Lan2Ip}:48888";
+            var httpPort = device.HttpPort > 0 ? device.HttpPort : 48888;
+            var baseAddress = $"http://{device.Lan2Ip}:{httpPort}";
             var result = await _serverApiService.CheckHealthAsync(baseAddress, password, selectedAdapter?.IPv4Address ?? string.Empty);
             if (result.Success)
             {

+ 3 - 0
windows/NetworkTool.Client/Models/DiscoveredDevice.cs

@@ -19,6 +19,9 @@ public sealed class DiscoveredDevice
     [JsonPropertyName("lan2_ip")]
     public required string Lan2Ip { get; init; }
 
+    [JsonPropertyName("http_port")]
+    public required int HttpPort { get; init; }
+
     [JsonPropertyName("auth_required")]
     public required bool AuthRequired { get; init; }
 }

+ 4 - 0
windows/NetworkTool.Client/Services/DiscoveryService.cs

@@ -70,6 +70,7 @@ public sealed class DiscoveryService
                     ServerVersion = response.ServerVersion ?? string.Empty,
                     Mac = mac ?? string.Empty,
                     Lan2Ip = response.Lan2Ip,
+                    HttpPort = response.HttpPort,
                     AuthRequired = response.AuthRequired,
                 };
             }
@@ -120,6 +121,9 @@ public sealed class DiscoveryService
         [JsonPropertyName("lan2_ip")]
         public string? Lan2Ip { get; set; }
 
+        [JsonPropertyName("http_port")]
+        public int HttpPort { get; set; }
+
         [JsonPropertyName("auth_required")]
         public bool AuthRequired { get; set; }
     }