Fix proxy UI type errors
This commit is contained in:
parent
a479040651
commit
a46ca5052b
2 changed files with 50 additions and 33 deletions
|
|
@ -40,6 +40,12 @@ type TemperatureTransportDetail = {
|
||||||
disable?: boolean;
|
disable?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface ProxyInstallResponse {
|
||||||
|
command: string;
|
||||||
|
pulseURL: string;
|
||||||
|
node?: string;
|
||||||
|
}
|
||||||
|
|
||||||
const deriveNameFromHost = (host: string): string => {
|
const deriveNameFromHost = (host: string): string => {
|
||||||
let value = host.trim();
|
let value = host.trim();
|
||||||
if (!value) {
|
if (!value) {
|
||||||
|
|
@ -167,12 +173,14 @@ export const NodeModal: Component<NodeModalProps> = (props) => {
|
||||||
try {
|
try {
|
||||||
const nodeName = props.editingNode?.name ? encodeURIComponent(props.editingNode!.name) : '';
|
const nodeName = props.editingNode?.name ? encodeURIComponent(props.editingNode!.name) : '';
|
||||||
const query = nodeName ? `?node=${nodeName}` : '';
|
const query = nodeName ? `?node=${nodeName}` : '';
|
||||||
const response = await apiFetchJSON(`/api/temperature-proxy/install-command${query}`);
|
const response = (await apiFetchJSON(
|
||||||
|
`/api/temperature-proxy/install-command${query}`,
|
||||||
|
)) as ProxyInstallResponse;
|
||||||
if (!response || typeof response.command !== 'string') {
|
if (!response || typeof response.command !== 'string') {
|
||||||
throw new Error('Proxy installer command unavailable');
|
throw new Error('Proxy installer command unavailable');
|
||||||
}
|
}
|
||||||
setProxyInstallCommand(response.command);
|
setProxyInstallCommand(response.command);
|
||||||
showSuccess('HTTPS proxy command ready', 2000);
|
showSuccess('HTTPS proxy command ready', undefined, 2000);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message =
|
const message =
|
||||||
error instanceof Error ? error.message : 'Failed to generate HTTPS proxy command';
|
error instanceof Error ? error.message : 'Failed to generate HTTPS proxy command';
|
||||||
|
|
|
||||||
|
|
@ -998,15 +998,16 @@ const Settings: Component<SettingsProps> = (props) => {
|
||||||
const diag = await response.json();
|
const diag = await response.json();
|
||||||
setDiagnosticsData(diag);
|
setDiagnosticsData(diag);
|
||||||
emitTemperatureProxyWarnings(diag);
|
emitTemperatureProxyWarnings(diag);
|
||||||
if (diag?.temperatureProxy?.hostProxySummary) {
|
setHostProxyStatus(
|
||||||
setHostProxyStatus({
|
diag?.temperatureProxy?.hostProxySummary
|
||||||
hostSocketPresent: Boolean(diag.temperatureProxy?.socketFound),
|
? {
|
||||||
containerSocketPresent: Boolean(
|
hostSocketPresent: Boolean(diag.temperatureProxy?.socketFound),
|
||||||
diag.temperatureProxy?.hostProxySummary?.containerSocketPresent ?? false,
|
containerSocketPresent:
|
||||||
),
|
diag.temperatureProxy?.hostProxySummary?.containerSocketPresent ?? undefined,
|
||||||
summary: diag.temperatureProxy?.hostProxySummary ?? undefined,
|
summary: diag.temperatureProxy?.hostProxySummary ?? undefined,
|
||||||
});
|
}
|
||||||
}
|
: null,
|
||||||
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error('Failed to fetch diagnostics', err);
|
logger.error('Failed to fetch diagnostics', err);
|
||||||
showError('Failed to run diagnostics');
|
showError('Failed to run diagnostics');
|
||||||
|
|
@ -1022,7 +1023,7 @@ const Settings: Component<SettingsProps> = (props) => {
|
||||||
)) as HostProxyStatusResponse;
|
)) as HostProxyStatusResponse;
|
||||||
setHostProxyStatus(status);
|
setHostProxyStatus(status);
|
||||||
if (notify) {
|
if (notify) {
|
||||||
showSuccess('Host proxy status refreshed', 2000);
|
showSuccess('Host proxy status refreshed', undefined, 2000);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error('Failed to refresh host proxy status', err);
|
logger.error('Failed to refresh host proxy status', err);
|
||||||
|
|
@ -5602,7 +5603,11 @@ const Settings: Component<SettingsProps> = (props) => {
|
||||||
const command = status().reinstallCommand;
|
const command = status().reinstallCommand;
|
||||||
if (command) {
|
if (command) {
|
||||||
void copyToClipboard(command);
|
void copyToClipboard(command);
|
||||||
showSuccess('Host proxy command copied', 2000);
|
showSuccess(
|
||||||
|
'Host proxy command copied',
|
||||||
|
undefined,
|
||||||
|
2000,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
@ -6213,6 +6218,8 @@ const Settings: Component<SettingsProps> = (props) => {
|
||||||
const suffix = suffixMatch ? suffixMatch[0] : '';
|
const suffix = suffixMatch ? suffixMatch[0] : '';
|
||||||
return `node-REDACTED${suffix}`;
|
return `node-REDACTED${suffix}`;
|
||||||
};
|
};
|
||||||
|
const sanitizeOptionalHostname = (value?: string) =>
|
||||||
|
value && value.trim() ? sanitizeHostname(value) : undefined;
|
||||||
|
|
||||||
const sanitizeText = (text: string | undefined) => {
|
const sanitizeText = (text: string | undefined) => {
|
||||||
if (!text) return text;
|
if (!text) return text;
|
||||||
|
|
@ -6469,26 +6476,28 @@ const Settings: Component<SettingsProps> = (props) => {
|
||||||
if (Array.isArray(proxyDiag.socketHostCooldowns)) {
|
if (Array.isArray(proxyDiag.socketHostCooldowns)) {
|
||||||
proxyDiag.socketHostCooldowns = (
|
proxyDiag.socketHostCooldowns = (
|
||||||
proxyDiag.socketHostCooldowns as Array<Record<string, unknown>>
|
proxyDiag.socketHostCooldowns as Array<Record<string, unknown>>
|
||||||
).map((entry) => ({
|
).map((entry) => {
|
||||||
node: sanitizeHostname(
|
const originalNode =
|
||||||
typeof entry.node === 'string' ? (entry.node as string) : undefined,
|
typeof entry.node === 'string' ? (entry.node as string) : undefined;
|
||||||
) as string,
|
const originalHost =
|
||||||
host: sanitizeHostname(
|
typeof entry.host === 'string' ? (entry.host as string) : undefined;
|
||||||
typeof entry.host === 'string' ? (entry.host as string) : undefined,
|
return {
|
||||||
) as string,
|
node: sanitizeOptionalHostname(originalNode),
|
||||||
cooldownUntil:
|
host: sanitizeOptionalHostname(originalHost),
|
||||||
typeof entry.cooldownUntil === 'string'
|
cooldownUntil:
|
||||||
? (entry.cooldownUntil as string)
|
typeof entry.cooldownUntil === 'string'
|
||||||
: undefined,
|
? (entry.cooldownUntil as string)
|
||||||
secondsRemaining:
|
: undefined,
|
||||||
typeof entry.secondsRemaining === 'number'
|
secondsRemaining:
|
||||||
? (entry.secondsRemaining as number)
|
typeof entry.secondsRemaining === 'number'
|
||||||
: undefined,
|
? (entry.secondsRemaining as number)
|
||||||
lastError:
|
: undefined,
|
||||||
typeof entry.lastError === 'string'
|
lastError:
|
||||||
? sanitizeText(entry.lastError as string) ?? (entry.lastError as string)
|
typeof entry.lastError === 'string'
|
||||||
: undefined,
|
? sanitizeText(entry.lastError as string) ?? (entry.lastError as string)
|
||||||
}));
|
: undefined,
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue