diff --git a/packages/uhk-agent/src/util/save-extract-firmware.ts b/packages/uhk-agent/src/util/save-extract-firmware.ts index 331f51e3719..8b8e1fc5287 100644 --- a/packages/uhk-agent/src/util/save-extract-firmware.ts +++ b/packages/uhk-agent/src/util/save-extract-firmware.ts @@ -4,6 +4,7 @@ import { dirSync } from 'tmp'; import decompress from 'decompress'; import decompressTarbz from 'decompress-tarbz2'; import decompressTargz from 'decompress-targz'; +import decompressUnzip from 'decompress-unzip'; import { UploadFileData } from 'uhk-common'; import { TmpFirmware } from 'uhk-usb'; @@ -26,6 +27,28 @@ export async function saveTmpFirmware(fileData: UploadFileData): Promise { + const fileName = path.basename(file.path); + + return fileName.startsWith('uhk-firmware-') && fileName.endsWith('.tar.gz'); + }, + plugins: [decompressUnzip()] + } + + const unzippedFiles = await decompress(zipFilePath, tmpDirectory.name, unzipOptions); + if (unzippedFiles.length === 0) { + throw new Error('Zip file does not contain uhk-firmware-*.tar.gz file.'); + } + + return saveTmpFirmware({ + data: unzippedFiles[0].data as any, + filename: path.basename(unzippedFiles[0].path), + saveInHistory: fileData.saveInHistory, + }) + } + default: throw new Error(`Unsupported firmware file extension: ${extension}`); } diff --git a/packages/uhk-web/src/app/components/device/firmware-file-upload/firmware-file-upload.component.html b/packages/uhk-web/src/app/components/device/firmware-file-upload/firmware-file-upload.component.html index 29f316dcef8..7fc5bea1c27 100644 --- a/packages/uhk-web/src/app/components/device/firmware-file-upload/firmware-file-upload.component.html +++ b/packages/uhk-web/src/app/components/device/firmware-file-upload/firmware-file-upload.component.html @@ -13,11 +13,11 @@ (confirm)="onForceClick()" (isOpenChange)="onOpenChange($event)" > - Flash firmware from file (uhk-firmware-*.tar.gz) + Flash firmware from file (uhk-firmware-*.tar.gz, firmware*.zip)