+21
-13
@@ -7,30 +7,37 @@ const hasWebProxyAvailable = (hass: HomeAssistant): boolean => {
|
||||
return hass.config.components.includes(HASS_WEB_PROXY_DOMAIN);
|
||||
};
|
||||
|
||||
export const getWebProxiedURL = (url: string, v?: number): string => {
|
||||
return `/api/${HASS_WEB_PROXY_DOMAIN}/v${v ?? 0}/?url=${encodeURIComponent(url)}`;
|
||||
interface ProxiedURLOptions {
|
||||
version?: number;
|
||||
websocket?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a proxied URL for the given URL.
|
||||
* @param url The URL to proxy.
|
||||
* @param options Options for the proxied URL.
|
||||
* @returns The proxied URL.
|
||||
*/
|
||||
export const getWebProxiedURL = (url: string, options?: ProxiedURLOptions): string => {
|
||||
return (
|
||||
`/api/${HASS_WEB_PROXY_DOMAIN}/v${options?.version ?? 0}/` +
|
||||
`${options?.websocket ? 'ws' : ''}?url=${encodeURIComponent(url)}`
|
||||
);
|
||||
};
|
||||
|
||||
export const shouldUseWebProxy = (
|
||||
hass: HomeAssistant,
|
||||
proxyConfig: CameraProxyConfig,
|
||||
context: 'media' = 'media',
|
||||
context: 'media' | 'live' = 'media',
|
||||
): boolean => {
|
||||
return hasWebProxyAvailable(hass) && !!proxyConfig[context];
|
||||
};
|
||||
|
||||
/**
|
||||
* Request that HA sign a path. May throw.
|
||||
* @param hass The HomeAssistant object used to request the signature.
|
||||
* @param path The path to sign.
|
||||
* @param expires An optional number of seconds to sign the path for (by default
|
||||
* HA will sign for 30 seconds).
|
||||
* @returns The signed URL, or null if the response was malformed.
|
||||
*/
|
||||
export async function addDynamicProxyURL(
|
||||
hass: HomeAssistant,
|
||||
url_pattern: string,
|
||||
options?: {
|
||||
proxyConfig?: CameraProxyConfig;
|
||||
urlID?: string;
|
||||
sslVerification?: boolean;
|
||||
sslCiphers?: string;
|
||||
@@ -43,8 +50,9 @@ export async function addDynamicProxyURL(
|
||||
url_pattern: url_pattern,
|
||||
...(options && {
|
||||
url_id: options.urlID,
|
||||
ssl_verification: options.sslVerification,
|
||||
ssl_ciphers: options.sslCiphers,
|
||||
ssl_verification:
|
||||
options.sslVerification ?? options?.proxyConfig?.ssl_verification,
|
||||
ssl_ciphers: options.sslCiphers ?? options?.proxyConfig?.ssl_ciphers,
|
||||
open_limit: options.openLimit,
|
||||
ttl: options.ttl,
|
||||
allow_unauthenticated: options.allowUnauthenticated,
|
||||
|
||||
Reference in New Issue
Block a user