Use download util for diagnostics (#11349)

This commit is contained in:
Paulus Schoutsen 2022-01-17 23:52:29 -08:00 committed by GitHub
parent 2d651c2a66
commit f3642a1677
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 10 deletions

View File

@ -330,7 +330,6 @@ class HassioBackupDialog
} }
fileDownload( fileDownload(
this,
signedPath.path, signedPath.path,
`home_assistant_backup_${slugify(this._computeName)}.tar` `home_assistant_backup_${slugify(this._computeName)}.tar`
); );

View File

@ -45,6 +45,7 @@ import {
} from "../../../dialogs/generic/show-dialog-box"; } from "../../../dialogs/generic/show-dialog-box";
import { haStyle, haStyleScrollbar } from "../../../resources/styles"; import { haStyle, haStyleScrollbar } from "../../../resources/styles";
import type { HomeAssistant } from "../../../types"; import type { HomeAssistant } from "../../../types";
import { fileDownload } from "../../../util/file_download";
import type { ConfigEntryExtended } from "./ha-config-integrations"; import type { ConfigEntryExtended } from "./ha-config-integrations";
import "./ha-integration-header"; import "./ha-integration-header";
@ -647,7 +648,7 @@ export class HaIntegrationCard extends LitElement {
this.hass, this.hass,
anchor.getAttribute("href") anchor.getAttribute("href")
); );
document.location.assign(signedUrl.path); fileDownload(signedUrl.path);
} }
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {

View File

@ -131,7 +131,6 @@ class ZWaveJSLogs extends SubscribeMixin(LitElement) {
private _downloadLogs() { private _downloadLogs() {
fileDownload( fileDownload(
this,
`data:text/plain;charset=utf-8,${encodeURIComponent( `data:text/plain;charset=utf-8,${encodeURIComponent(
this._textarea!.value this._textarea!.value
)}`, )}`,

View File

@ -1,14 +1,10 @@
export const fileDownload = ( export const fileDownload = (href: string, filename = ""): void => {
element: HTMLElement,
href: string,
filename: string
): void => {
const a = document.createElement("a"); const a = document.createElement("a");
a.target = "_blank"; a.target = "_blank";
a.href = href; a.href = href;
a.download = filename; a.download = filename;
element.shadowRoot!.appendChild(a); document.body.appendChild(a);
a.dispatchEvent(new MouseEvent("click")); a.dispatchEvent(new MouseEvent("click"));
element.shadowRoot!.removeChild(a); document.body.removeChild(a);
}; };