From 03f7c674fabdb8a54ae9620f039e4124f49cd338 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Fri, 11 Jun 2021 10:20:00 +0200 Subject: [PATCH] Fixed the bug that cause the file transfer to timeout if the user hasn't been quick enough to save his file --- shared/js/file/FileManager.tsx | 26 ++++++++++++++----- .../transfer/FileBrowserControllerRemote.ts | 9 ++++--- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/shared/js/file/FileManager.tsx b/shared/js/file/FileManager.tsx index 6054bbcd..ecb78b45 100644 --- a/shared/js/file/FileManager.tsx +++ b/shared/js/file/FileManager.tsx @@ -549,9 +549,11 @@ export class FileManager { const initializeCallback = async () => { try { transfer.target = await transfer.targetSupplier(transfer); - if(!transfer.target) + if(!transfer.target) { throw tr("Failed to create transfer target"); + } + transfer.lastStateUpdate = Date.now(); await this.connectionHandler.serverConnection.send_command("ftinitdownload", { "path": options.path, "name": options.name, @@ -565,7 +567,6 @@ export class FileManager { if(transfer.transferState() === FileTransferState.INITIALIZING) { throw tr("missing transfer start notify"); } - } catch (error) { transfer.setFailed({ error: "initialize", @@ -588,9 +589,11 @@ export class FileManager { const initializeCallback = async () => { try { transfer.source = await transfer.sourceSupplier(transfer); - if(!transfer.source) + if(!transfer.source) { throw tr("Failed to create transfer source"); + } + transfer.lastStateUpdate = Date.now(); transfer.fileSize = await transfer.source.fileSize(); await this.connectionHandler.serverConnection.send_command("ftinitupload", { "path": options.path, @@ -604,14 +607,15 @@ export class FileManager { "proto": 1 }, { process_result: options.processCommandResult }); - if(transfer.transferState() === FileTransferState.INITIALIZING) + if(transfer.transferState() === FileTransferState.INITIALIZING) { throw tr("missing transfer start notify"); + } } catch (error) { transfer.setFailed({ error: "initialize", commandResult: error - }, error instanceof CommandResult ? error.formattedMessage() : typeof error === "string" ? error : tr("Lookup the console")); + }, error instanceof CommandResult ? error.formattedMessage() : typeof error === "string" ? error : tr("lookup the console")); } }; @@ -735,8 +739,18 @@ export class FileManager { /* Transfer is locally pending because of some limits */ return false; - case FileTransferState.CONNECTING: case FileTransferState.INITIALIZING: + if(entry instanceof FileDownloadTransfer) { + if(!entry.target) { + /* We're still prompting the user for a target file location. Lets apply a timeout of 1 min. */ + if(entry.transfer.lastStateUpdate < Date.now() + 60 * 1000) { + return false; + } + } + } + return true; + + case FileTransferState.CONNECTING: case FileTransferState.RUNNING: /* These states can time out */ return true; diff --git a/shared/js/ui/modal/transfer/FileBrowserControllerRemote.ts b/shared/js/ui/modal/transfer/FileBrowserControllerRemote.ts index dd7485b2..c5fdc324 100644 --- a/shared/js/ui/modal/transfer/FileBrowserControllerRemote.ts +++ b/shared/js/ui/modal/transfer/FileBrowserControllerRemote.ts @@ -686,12 +686,13 @@ export function initializeRemoteFileBrowserController(connection: ConnectionHand }); }); - events.on("action_start_download", event => { - event.files.forEach(file => { + events.on("action_start_download", async event => { + for(const file of event.files) { try { let targetSupplier; if (__build.target === "client" && TransferProvider.provider().targetSupported(TransferTargetType.FILE)) { - const target = TransferProvider.provider().createFileTarget(undefined, file.name); + /* Get the target file path before we're actiually starting to download the file */ + const target = await TransferProvider.provider().createFileTarget(undefined, file.name); targetSupplier = async () => target; } else if (TransferProvider.provider().targetSupported(TransferTargetType.DOWNLOAD)) { targetSupplier = async () => await TransferProvider.provider().createDownloadTarget(); @@ -717,7 +718,7 @@ export function initializeRemoteFileBrowserController(connection: ConnectionHand } catch (error) { logError(LogCategory.FILE_TRANSFER, tr("Failed to parse path for file download: %s"), error); } - }); + } }); events.on("action_start_upload", event => {