From d0e947ca02cc25f120ddbb365332dda9c3871698 Mon Sep 17 00:00:00 2001 From: ila <2+ila@noreply.git.ilapage.cn> Date: Thu, 13 Aug 2026 12:23:42 +0800 Subject: [PATCH] feat: complete split camera credentials (#50) --- .../server/app/sense/adapters/onvif/client.go | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Sense/server/app/sense/adapters/onvif/client.go b/Sense/server/app/sense/adapters/onvif/client.go index ffae991..1f5acc9 100644 --- a/Sense/server/app/sense/adapters/onvif/client.go +++ b/Sense/server/app/sense/adapters/onvif/client.go @@ -9,6 +9,7 @@ import ( "encoding/xml" "fmt" "io" + "net" "net/http" "net/url" "strconv" @@ -82,9 +83,32 @@ func (c *HTTPClient) Profiles(ctx context.Context, address string, credential Cr if err != nil { return nil, err } + profiles[i].StreamURI, err = normalizeStreamURI(deviceEndpoint, profiles[i].StreamURI) + if err != nil { + return nil, err + } } return profiles, nil } + +func normalizeStreamURI(deviceEndpoint, streamURI string) (string, error) { + device, err := url.Parse(deviceEndpoint) + if err != nil || device.Hostname() == "" { + return "", fmt.Errorf("invalid ONVIF address") + } + stream, err := url.Parse(streamURI) + if err != nil || stream.Scheme != "rtsp" || stream.Host == "" || stream.User != nil { + return "", fmt.Errorf("invalid RTSP stream URI") + } + if !strings.EqualFold(stream.Hostname(), device.Hostname()) { + port := stream.Port() + stream.Host = device.Hostname() + if port != "" { + stream.Host = net.JoinHostPort(device.Hostname(), port) + } + } + return stream.String(), nil +} func (c *HTTPClient) soap(ctx context.Context, endpoint string, credential Credential, body string) ([]byte, error) { return c.soapAttempt(ctx, endpoint, credential, body, "") }