fix: decode XML entities in ONVIF RTSP URIs

ONVIF returns XML with & in URIs. GStreamer rtspsrc cant parse
these. Now decoded before storing in camera_streams. Fixes RTSP
Unauthorized for ONVIF-discovered cameras with query params.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Mitchell R 2026-05-26 06:44:25 +02:00
parent 2a21ababc0
commit b6e929d2ad
No known key found for this signature in database

View file

@ -112,15 +112,17 @@ async function uniqueCameraName(deps: AdminDeps, rawName: string): Promise<strin
} }
function rtspWithCredentials(raw: string, username: string, password: string): string { function rtspWithCredentials(raw: string, username: string, password: string): string {
if (!username) return raw; // ONVIF returns XML — URIs may contain &amp; instead of &
let clean = raw.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">");
if (!username) return clean;
try { try {
const url = new URL(raw); const url = new URL(clean);
if (url.protocol !== "rtsp:" || url.username) return raw; if (url.protocol !== "rtsp:" || url.username) return clean;
url.username = username; url.username = username;
url.password = password; url.password = password;
return url.toString(); return url.toString();
} catch { } catch {
return raw; return clean;
} }
} }