Refactor to Home Assistant integration using WebSockets and HTTP Proxy View

This commit is contained in:
2025-12-19 02:40:27 +10:00
parent 0cbc6a7a7c
commit 212bf5b18f
28 changed files with 3895 additions and 266 deletions
+11 -16
View File
@@ -1,25 +1,20 @@
/**
* Resolves a URL relative to the service URL if it's a relative path
* Service returns relative URLs like "/api/radar/.../frame/..." which need
* to be resolved against the service_url base
* Resolves a URL through the Home Assistant integration proxy if it's a relative path.
* The integration provides a proxy at /api/bom_local/proxy/
*/
export function resolveImageUrl(url: string, serviceUrl: string): string {
export function resolveImageUrl(url: string, serviceUrl?: string): string {
if (!url) return url;
// If URL is already absolute (starts with http:// or https://), use as-is
if (url.startsWith('http://') || url.startsWith('https://')) {
return url;
}
// Remove trailing slash from serviceUrl
const baseUrl = serviceUrl.replace(/\/$/, '');
// If URL is relative (starts with /), resolve against service URL
if (url.startsWith('/')) {
return `${baseUrl}${url}`;
}
// If URL is relative without leading slash, resolve against service URL with path
return `${baseUrl}/${url}`;
}
// If we are using the HA integration proxy (standard behavior now)
const proxyPrefix = '/api/bom_local/proxy';
// Remove leading slash if present to avoid double slashes
const path = url.startsWith('/') ? url : `/${url}`;
return `${proxyPrefix}${path}`;
}