Skip to content

Commit

Permalink
Fix load older logs at boot 0 in error-log-card (#22657)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
wendevlin authored Nov 4, 2024
1 parent 2f97407 commit 0b38143
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 44 deletions.
27 changes: 4 additions & 23 deletions src/data/hassio/supervisor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
? {
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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,
Expand Down
14 changes: 2 additions & 12 deletions src/panels/config/logs/dialog-download-logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
10 changes: 1 addition & 9 deletions src/panels/config/logs/error-log-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import { extractApiErrorMessage } from "../../../data/hassio/common";
import {
fetchHassioBoots,
fetchHassioLogs,
fetchHassioLogsBootFollow,
fetchHassioLogsFollow,
getHassioLogDownloadUrl,
} from "../../../data/hassio/supervisor";
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 0b38143

Please sign in to comment.