mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Add fallback for missing logs boot result. (#22600)
* Add fallback for missing logs boot result. * Add fallback for logs full download when boots are missing * Fix function naming and single boot select in error-log-card
This commit is contained in:
parent
eb8d23320a
commit
744cda3974
@ -203,6 +203,20 @@ export const fetchHassioLogs = async (
|
|||||||
);
|
);
|
||||||
|
|
||||||
export const fetchHassioLogsFollow = 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,
|
hass: HomeAssistant,
|
||||||
provider: string,
|
provider: string,
|
||||||
signal: AbortSignal,
|
signal: AbortSignal,
|
||||||
@ -222,7 +236,12 @@ export const getHassioLogDownloadUrl = (provider: string) =>
|
|||||||
provider.includes("_") ? `addons/${provider}` : provider
|
provider.includes("_") ? `addons/${provider}` : provider
|
||||||
}/logs`;
|
}/logs`;
|
||||||
|
|
||||||
export const getHassioLogDownloadLinesUrl = (
|
export const getHassioLogDownloadLinesUrl = (provider: string, lines: number) =>
|
||||||
|
`/api/hassio/${
|
||||||
|
provider.includes("_") ? `addons/${provider}` : provider
|
||||||
|
}/logs?lines=${lines}`;
|
||||||
|
|
||||||
|
export const getHassioLogBootDownloadLinesUrl = (
|
||||||
provider: string,
|
provider: string,
|
||||||
lines: number,
|
lines: number,
|
||||||
boot = 0
|
boot = 0
|
||||||
|
@ -14,7 +14,10 @@ import type { DownloadLogsDialogParams } from "./show-dialog-download-logs";
|
|||||||
import "../../../components/ha-select";
|
import "../../../components/ha-select";
|
||||||
import "../../../components/ha-list-item";
|
import "../../../components/ha-list-item";
|
||||||
import { stopPropagation } from "../../../common/dom/stop_propagation";
|
import { stopPropagation } from "../../../common/dom/stop_propagation";
|
||||||
import { getHassioLogDownloadLinesUrl } from "../../../data/hassio/supervisor";
|
import {
|
||||||
|
getHassioLogDownloadLinesUrl,
|
||||||
|
getHassioLogBootDownloadLinesUrl,
|
||||||
|
} from "../../../data/hassio/supervisor";
|
||||||
import { getSignedPath } from "../../../data/auth";
|
import { getSignedPath } from "../../../data/auth";
|
||||||
import { fileDownload } from "../../../util/file_download";
|
import { fileDownload } from "../../../util/file_download";
|
||||||
|
|
||||||
@ -112,7 +115,7 @@ class DownloadLogsDialog extends LitElement {
|
|||||||
const boot = this._dialogParams!.boot;
|
const boot = this._dialogParams!.boot;
|
||||||
|
|
||||||
const timeString = new Date().toISOString().replace(/:/g, "-");
|
const timeString = new Date().toISOString().replace(/:/g, "-");
|
||||||
const downloadUrl = getHassioLogDownloadLinesUrl(
|
const downloadUrl = this._getDownloadUrlFunction()(
|
||||||
provider,
|
provider,
|
||||||
this._lineCount,
|
this._lineCount,
|
||||||
boot
|
boot
|
||||||
@ -126,6 +129,13 @@ class DownloadLogsDialog extends LitElement {
|
|||||||
this.closeDialog();
|
this.closeDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _getDownloadUrlFunction() {
|
||||||
|
if (this._dialogParams!.boot === 0) {
|
||||||
|
return getHassioLogDownloadLinesUrl;
|
||||||
|
}
|
||||||
|
return getHassioLogBootDownloadLinesUrl;
|
||||||
|
}
|
||||||
|
|
||||||
private _setNumberOfLogs(ev) {
|
private _setNumberOfLogs(ev) {
|
||||||
this._lineCount = Number(ev.target.value);
|
this._lineCount = Number(ev.target.value);
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ import { extractApiErrorMessage } from "../../../data/hassio/common";
|
|||||||
import {
|
import {
|
||||||
fetchHassioBoots,
|
fetchHassioBoots,
|
||||||
fetchHassioLogs,
|
fetchHassioLogs,
|
||||||
|
fetchHassioLogsBootFollow,
|
||||||
fetchHassioLogsFollow,
|
fetchHassioLogsFollow,
|
||||||
getHassioLogDownloadUrl,
|
getHassioLogDownloadUrl,
|
||||||
} from "../../../data/hassio/supervisor";
|
} from "../../../data/hassio/supervisor";
|
||||||
@ -378,7 +379,7 @@ class ErrorLogCard extends LitElement {
|
|||||||
isComponentLoaded(this.hass, "hassio") &&
|
isComponentLoaded(this.hass, "hassio") &&
|
||||||
this.provider
|
this.provider
|
||||||
) {
|
) {
|
||||||
const response = await fetchHassioLogsFollow(
|
const response = await this._fetchLogsFunction()(
|
||||||
this.hass,
|
this.hass,
|
||||||
this.provider,
|
this.provider,
|
||||||
this._logStreamAborter.signal,
|
this._logStreamAborter.signal,
|
||||||
@ -468,6 +469,13 @@ class ErrorLogCard extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _fetchLogsFunction = () => {
|
||||||
|
if (this._boot === 0) {
|
||||||
|
return fetchHassioLogsFollow;
|
||||||
|
}
|
||||||
|
return fetchHassioLogsBootFollow;
|
||||||
|
};
|
||||||
|
|
||||||
private _debounceSearch = debounce(() => {
|
private _debounceSearch = debounce(() => {
|
||||||
this._noSearchResults = !this._ansiToHtmlElement?.filterLines(this.filter);
|
this._noSearchResults = !this._ansiToHtmlElement?.filterLines(this.filter);
|
||||||
|
|
||||||
@ -570,9 +578,14 @@ class ErrorLogCard extends LitElement {
|
|||||||
if (this._streamSupported && isComponentLoaded(this.hass, "hassio")) {
|
if (this._streamSupported && isComponentLoaded(this.hass, "hassio")) {
|
||||||
try {
|
try {
|
||||||
const { data } = await fetchHassioBoots(this.hass);
|
const { data } = await fetchHassioBoots(this.hass);
|
||||||
this._boots = Object.keys(data.boots)
|
const boots = Object.keys(data.boots)
|
||||||
.map(Number)
|
.map(Number)
|
||||||
.sort((a, b) => b - a);
|
.sort((a, b) => b - a);
|
||||||
|
|
||||||
|
// only show boots select when there are more than one boot
|
||||||
|
if (boots.length > 1) {
|
||||||
|
this._boots = boots;
|
||||||
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user