diff --git a/hassio/src/components/hassio-upload-backup.ts b/hassio/src/components/hassio-upload-backup.ts index 70b326bff9..ae19a12c81 100644 --- a/hassio/src/components/hassio-upload-backup.ts +++ b/hassio/src/components/hassio-upload-backup.ts @@ -16,11 +16,9 @@ declare global { } } -const MAX_FILE_SIZE = 1 * 1024 * 1024 * 1024; // 1GB - @customElement("hassio-upload-backup") export class HassioUploadBackup extends LitElement { - public hass!: HomeAssistant; + public hass?: HomeAssistant; @state() public value: string | null = null; @@ -43,20 +41,6 @@ export class HassioUploadBackup extends LitElement { private async _uploadFile(ev) { const file = ev.detail.files[0]; - if (file.size > MAX_FILE_SIZE) { - showAlertDialog(this, { - title: "Backup file is too big", - text: html`The maximum allowed filesize is 1GB.
- Have a look here on how to restore it.`, - confirmText: "ok", - }); - return; - } - if (!["application/x-tar"].includes(file.type)) { showAlertDialog(this, { title: "Unsupported file format", diff --git a/hassio/src/dialogs/backup/dialog-hassio-backup-upload.ts b/hassio/src/dialogs/backup/dialog-hassio-backup-upload.ts index 2b835f0ad9..4fd6751d36 100644 --- a/hassio/src/dialogs/backup/dialog-hassio-backup-upload.ts +++ b/hassio/src/dialogs/backup/dialog-hassio-backup-upload.ts @@ -15,7 +15,7 @@ export class DialogHassioBackupUpload extends LitElement implements HassDialog { - @property({ attribute: false }) public hass!: HomeAssistant; + @property({ attribute: false }) public hass?: HomeAssistant; @state() private _params?: HassioBackupUploadDialogParams; @@ -54,7 +54,7 @@ export class DialogHassioBackupUpload Upload backup { - @property({ attribute: false }) public hass!: HomeAssistant; + @property({ attribute: false }) public hass?: HomeAssistant; @state() private _error?: string; @@ -77,7 +77,7 @@ class HassioBackupDialog ${this._backup.name} @@ -192,25 +192,23 @@ class HassioBackupDialog } if (!this._dialogParams?.onboarding) { - this.hass - .callApi( - "POST", + this.hass!.callApi( + "POST", - `hassio/${ - atLeastVersion(this.hass.config.version, 2021, 9) - ? "backups" - : "snapshots" - }/${this._backup!.slug}/restore/partial`, - backupDetails - ) - .then( - () => { - this.closeDialog(); - }, - (error) => { - this._error = error.body.message; - } - ); + `hassio/${ + atLeastVersion(this.hass!.config.version, 2021, 9) + ? "backups" + : "snapshots" + }/${this._backup!.slug}/restore/partial`, + backupDetails + ).then( + () => { + this.closeDialog(); + }, + (error) => { + this._error = error.body.message; + } + ); } else { fireEvent(this, "restoring"); fetch(`/api/hassio/backups/${this._backup!.slug}/restore/partial`, { @@ -244,24 +242,22 @@ class HassioBackupDialog } if (!this._dialogParams?.onboarding) { - this.hass - .callApi( - "POST", - `hassio/${ - atLeastVersion(this.hass.config.version, 2021, 9) - ? "backups" - : "snapshots" - }/${this._backup!.slug}/restore/full`, - backupDetails - ) - .then( - () => { - this.closeDialog(); - }, - (error) => { - this._error = error.body.message; - } - ); + this.hass!.callApi( + "POST", + `hassio/${ + atLeastVersion(this.hass!.config.version, 2021, 9) + ? "backups" + : "snapshots" + }/${this._backup!.slug}/restore/full`, + backupDetails + ).then( + () => { + this.closeDialog(); + }, + (error) => { + this._error = error.body.message; + } + ); } else { fireEvent(this, "restoring"); fetch(`/api/hassio/backups/${this._backup!.slug}/restore/full`, { @@ -283,36 +279,33 @@ class HassioBackupDialog return; } - this.hass - - .callApi( - atLeastVersion(this.hass.config.version, 2021, 9) ? "DELETE" : "POST", - `hassio/${ - atLeastVersion(this.hass.config.version, 2021, 9) - ? `backups/${this._backup!.slug}` - : `snapshots/${this._backup!.slug}/remove` - }` - ) - .then( - () => { - if (this._dialogParams!.onDelete) { - this._dialogParams!.onDelete(); - } - this.closeDialog(); - }, - (error) => { - this._error = error.body.message; + this.hass!.callApi( + atLeastVersion(this.hass!.config.version, 2021, 9) ? "DELETE" : "POST", + `hassio/${ + atLeastVersion(this.hass!.config.version, 2021, 9) + ? `backups/${this._backup!.slug}` + : `snapshots/${this._backup!.slug}/remove` + }` + ).then( + () => { + if (this._dialogParams!.onDelete) { + this._dialogParams!.onDelete(); } - ); + this.closeDialog(); + }, + (error) => { + this._error = error.body.message; + } + ); } private async _downloadClicked() { let signedPath: { path: string }; try { signedPath = await getSignedPath( - this.hass, + this.hass!, `/api/hassio/${ - atLeastVersion(this.hass.config.version, 2021, 9) + atLeastVersion(this.hass!.config.version, 2021, 9) ? "backups" : "snapshots" }/${this._backup!.slug}/download` diff --git a/src/components/ha-file-upload.ts b/src/components/ha-file-upload.ts index 611ff357d5..31dd853e06 100644 --- a/src/components/ha-file-upload.ts +++ b/src/components/ha-file-upload.ts @@ -17,7 +17,7 @@ declare global { @customElement("ha-file-upload") export class HaFileUpload extends LitElement { - @property({ attribute: false }) public hass!: HomeAssistant; + @property({ attribute: false }) public hass?: HomeAssistant; @property() public accept!: string; @@ -88,7 +88,8 @@ export class HaFileUpload extends LitElement { ` diff --git a/src/data/hassio/backup.ts b/src/data/hassio/backup.ts index b19d4c1c66..c5af101857 100644 --- a/src/data/hassio/backup.ts +++ b/src/data/hassio/backup.ts @@ -79,7 +79,7 @@ export const fetchHassioBackups = async ( }; export const fetchHassioBackupInfo = async ( - hass: HomeAssistant, + hass: HomeAssistant | undefined, backup: string ): Promise => { if (hass) { @@ -202,7 +202,7 @@ export const createHassioPartialBackup = async ( }; export const uploadBackup = async ( - hass: HomeAssistant, + hass: HomeAssistant | undefined, file: File ): Promise> => { const fd = new FormData();