From 0b381437652f1c7f4d74c657ddbf996bafc36e99 Mon Sep 17 00:00:00 2001 From: Wendelin <12148533+wendevlin@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:36:25 +0100 Subject: [PATCH] Fix load older logs at boot 0 in error-log-card (#22657) * Fix load older logs at boot 0 in error-log-card * Refactor fetch boot logs in error-log-card * Refactor download url boot logs in error-log-card --- src/data/hassio/supervisor.ts | 27 +++---------------- .../config/logs/dialog-download-logs.ts | 14 ++-------- src/panels/config/logs/error-log-card.ts | 10 +------ 3 files changed, 7 insertions(+), 44 deletions(-) diff --git a/src/data/hassio/supervisor.ts b/src/data/hassio/supervisor.ts index cc74a7fd70f8..a0966d1baeaa 100644 --- a/src/data/hassio/supervisor.ts +++ b/src/data/hassio/supervisor.ts @@ -193,7 +193,7 @@ export const fetchHassioLogs = async ( ) => hass.callApiRaw( "GET", - `hassio/${provider.includes("_") ? `addons/${provider}` : provider}/logs/boots/${boot}`, + `hassio/${provider.includes("_") ? `addons/${provider}` : provider}/logs${boot !== 0 ? `/boots/${boot}` : ""}`, undefined, range ? { @@ -203,20 +203,6 @@ export const fetchHassioLogs = async ( ); export const fetchHassioLogsFollow = async ( - hass: HomeAssistant, - provider: string, - signal: AbortSignal, - lines = 100 -) => - hass.callApiRaw( - "GET", - `hassio/${provider.includes("_") ? `addons/${provider}` : provider}/logs/follow?lines=${lines}`, - undefined, - undefined, - signal - ); - -export const fetchHassioLogsBootFollow = async ( hass: HomeAssistant, provider: string, signal: AbortSignal, @@ -225,7 +211,7 @@ export const fetchHassioLogsBootFollow = async ( ) => hass.callApiRaw( "GET", - `hassio/${provider.includes("_") ? `addons/${provider}` : provider}/logs/boots/${boot}/follow?lines=${lines}`, + `hassio/${provider.includes("_") ? `addons/${provider}` : provider}/logs${boot !== 0 ? `/boots/${boot}` : ""}/follow?lines=${lines}`, undefined, undefined, signal @@ -236,19 +222,14 @@ export const getHassioLogDownloadUrl = (provider: string) => provider.includes("_") ? `addons/${provider}` : provider }/logs`; -export const getHassioLogDownloadLinesUrl = (provider: string, lines: number) => - `/api/hassio/${ - provider.includes("_") ? `addons/${provider}` : provider - }/logs?lines=${lines}`; - -export const getHassioLogBootDownloadLinesUrl = ( +export const getHassioLogDownloadLinesUrl = ( provider: string, lines: number, boot = 0 ) => `/api/hassio/${ provider.includes("_") ? `addons/${provider}` : provider - }/logs/boots/${boot}?lines=${lines}`; + }/logs${boot !== 0 ? `/boots/${boot}` : ""}?lines=${lines}`; export const setSupervisorOption = async ( hass: HomeAssistant, diff --git a/src/panels/config/logs/dialog-download-logs.ts b/src/panels/config/logs/dialog-download-logs.ts index e4726e0528a6..fdd67e5a315b 100644 --- a/src/panels/config/logs/dialog-download-logs.ts +++ b/src/panels/config/logs/dialog-download-logs.ts @@ -14,10 +14,7 @@ import type { DownloadLogsDialogParams } from "./show-dialog-download-logs"; import "../../../components/ha-select"; import "../../../components/ha-list-item"; import { stopPropagation } from "../../../common/dom/stop_propagation"; -import { - getHassioLogDownloadLinesUrl, - getHassioLogBootDownloadLinesUrl, -} from "../../../data/hassio/supervisor"; +import { getHassioLogDownloadLinesUrl } from "../../../data/hassio/supervisor"; import { getSignedPath } from "../../../data/auth"; import { fileDownload } from "../../../util/file_download"; @@ -115,7 +112,7 @@ class DownloadLogsDialog extends LitElement { const boot = this._dialogParams!.boot; const timeString = new Date().toISOString().replace(/:/g, "-"); - const downloadUrl = this._getDownloadUrlFunction()( + const downloadUrl = getHassioLogDownloadLinesUrl( provider, this._lineCount, boot @@ -129,13 +126,6 @@ class DownloadLogsDialog extends LitElement { this.closeDialog(); } - private _getDownloadUrlFunction() { - if (this._dialogParams!.boot === 0) { - return getHassioLogDownloadLinesUrl; - } - return getHassioLogBootDownloadLinesUrl; - } - private _setNumberOfLogs(ev) { this._lineCount = Number(ev.target.value); } diff --git a/src/panels/config/logs/error-log-card.ts b/src/panels/config/logs/error-log-card.ts index 12994fe1e23f..259a87ca7d12 100644 --- a/src/panels/config/logs/error-log-card.ts +++ b/src/panels/config/logs/error-log-card.ts @@ -39,7 +39,6 @@ import { extractApiErrorMessage } from "../../../data/hassio/common"; import { fetchHassioBoots, fetchHassioLogs, - fetchHassioLogsBootFollow, fetchHassioLogsFollow, getHassioLogDownloadUrl, } from "../../../data/hassio/supervisor"; @@ -379,7 +378,7 @@ class ErrorLogCard extends LitElement { isComponentLoaded(this.hass, "hassio") && this.provider ) { - const response = await this._fetchLogsFunction()( + const response = await fetchHassioLogsFollow( this.hass, this.provider, this._logStreamAborter.signal, @@ -469,13 +468,6 @@ class ErrorLogCard extends LitElement { } } - private _fetchLogsFunction = () => { - if (this._boot === 0) { - return fetchHassioLogsFollow; - } - return fetchHassioLogsBootFollow; - }; - private _debounceSearch = debounce(() => { this._noSearchResults = !this._ansiToHtmlElement?.filterLines(this.filter);