mirror of
https://github.com/alexhopeoconnor/bom-local-card.git
synced 2026-10-22 02:42:08 +10:00
Refactor to Home Assistant integration using WebSockets and HTTP Proxy View
This commit is contained in:
+11
-16
@@ -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}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user