From 5355ca6ab61937d9d96878472ed5a0f1c00ed50f Mon Sep 17 00:00:00 2001 From: Oskar Michalkiewicz <32848134+OskarMichalkiewicz@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:32:00 +0000 Subject: [PATCH] [CP-2148][Files Manager] Center doesn't stops uploading files after device disconecting (#1389) --- .../commands/file-upload.command.ts | 4 +- .../services/file-manager.service.ts | 84 ++++++++----------- 2 files changed, 40 insertions(+), 48 deletions(-) diff --git a/packages/app/src/device-file-system/commands/file-upload.command.ts b/packages/app/src/device-file-system/commands/file-upload.command.ts index d2a0f86d71..86edee0d5c 100644 --- a/packages/app/src/device-file-system/commands/file-upload.command.ts +++ b/packages/app/src/device-file-system/commands/file-upload.command.ts @@ -28,7 +28,6 @@ export class FileUploadCommand extends BaseCommand { ): Promise> { let data: Buffer | Uint8Array const maxFileSize = 2000000000 - try { const fileSize = await this.fileSystemService.getFileSize(filePath) if (fileSize >= maxFileSize) { @@ -112,6 +111,9 @@ export class FileUploadCommand extends BaseCommand { chunkNo, data: chunkedBuffer.toString("base64"), }, + options: { + connectionTimeOut: 5000, + }, }) if (!response.ok) { diff --git a/packages/app/src/files-manager/services/file-manager.service.ts b/packages/app/src/files-manager/services/file-manager.service.ts index 04ba3d7c06..bb59956c4b 100644 --- a/packages/app/src/files-manager/services/file-manager.service.ts +++ b/packages/app/src/files-manager/services/file-manager.service.ts @@ -54,43 +54,38 @@ export class FileManagerService { directory, filePaths, }: UploadFilesInput): Promise> { - const results = [] - - for await (const filePath of filePaths) { - results.push(await this.fileUploadCommand.exec(directory, filePath)) - } - - const success = results.every((result) => result.ok) - const noSpaceLeft = results.some( - (result) => result.error?.type === DeviceFileSystemError.NoSpaceLeft - ) - const unsupportedFileSize = results.some( - (result) => - result.error?.type === DeviceFileSystemError.UnsupportedFileSize - ) - - if (noSpaceLeft) { - return Result.failed( - new AppError( - FilesManagerError.NotEnoughSpace, - "Not enough space on your device" + for (const filePath of filePaths) { + try { + const { error, ok } = await this.fileUploadCommand.exec( + directory, + filePath ) - ) - } - - if (unsupportedFileSize) { - return Result.failed( - new AppError( - FilesManagerError.UnsupportedFileSize, - "Unsupported file size" + if (error?.type === DeviceFileSystemError.NoSpaceLeft) { + return Result.failed( + new AppError( + FilesManagerError.NotEnoughSpace, + "Not enough space on your device" + ) + ) + } + if (error?.type === DeviceFileSystemError.UnsupportedFileSize) { + return Result.failed( + new AppError( + FilesManagerError.UnsupportedFileSize, + "Unsupported file size" + ) + ) + } + if (!ok) { + return Result.failed( + new AppError(FilesManagerError.UploadFiles, "Upload failed") + ) + } + } catch (error) { + return Result.failed( + new AppError(FilesManagerError.UploadFiles, "Upload failed") ) - ) - } - - if (!success) { - return Result.failed( - new AppError(FilesManagerError.UploadFiles, "Upload failed") - ) + } } return Result.success(filePaths) @@ -99,18 +94,13 @@ export class FileManagerService { public async deleteFiles( filePaths: string[] ): Promise> { - const results = [] - - for await (const filePath of filePaths) { - results.push(await this.fileDeleteCommand.exec(filePath)) - } - - const success = results.every((result) => result.ok) - - if (!success) { - return Result.failed( - new AppError(FilesManagerError.DeleteFiles, "Delete failed") - ) + for (const filePath of filePaths) { + const { ok } = await this.fileDeleteCommand.exec(filePath) + if (!ok) { + return Result.failed( + new AppError(FilesManagerError.DeleteFiles, "Delete failed") + ) + } } return Result.success(filePaths)