From 7e288f7c903f6da4d1b66170efae54981ff3451d Mon Sep 17 00:00:00 2001 From: liu <362165265@qq.com> Date: Tue, 3 Feb 2026 11:18:14 +0800 Subject: [PATCH] Enhance file transfer functionality by updating error handling in FileController and improving UI interactions in index.html and app.js. Added specific error messages for different transfer scenarios and refactored transfer functions for clarity and usability. --- .../manager/controller/FileController.java | 19 ++++++++++++--- src/main/resources/static/index.html | 3 ++- src/main/resources/static/js/app.js | 24 ++++++++++++------- src/main/resources/templates/index.html | 3 ++- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/sftp/manager/controller/FileController.java b/src/main/java/com/sftp/manager/controller/FileController.java index e15802c..e910e34 100644 --- a/src/main/java/com/sftp/manager/controller/FileController.java +++ b/src/main/java/com/sftp/manager/controller/FileController.java @@ -201,10 +201,10 @@ public class FileController { // 本地到本地 Files.copy(new File(sourcePath).toPath(), new File(finalTargetPath).toPath()); } else if ("local".equals(sourceSessionId)) { - // 本地到SFTP + // 本地到SFTP(上传到服务器) localFileService.uploadToSftp(sourcePath, targetSessionId, finalTargetPath, sftpService); } else if ("local".equals(targetSessionId)) { - // SFTP到本地 + // SFTP到本地(从服务器下载) localFileService.downloadFromSftp(sourceSessionId, sourcePath, finalTargetPath, sftpService); } else { // SFTP到SFTP @@ -214,7 +214,20 @@ public class FileController { return ApiResponse.success("传输成功", null); } catch (Exception e) { - return ApiResponse.error("传输失败: " + e.getMessage()); + String msg = e.getMessage() != null ? e.getMessage() : "未知错误"; + String src = request.getSourceSessionId(); + String tgt = request.getTargetSessionId(); + String prefix; + if ("local".equals(src) && !"local".equals(tgt)) { + prefix = "上传到服务器失败"; + } else if (!"local".equals(src) && "local".equals(tgt)) { + prefix = "下载到本地失败"; + } else if (!"local".equals(src) && !"local".equals(tgt)) { + prefix = "服务器间传输失败"; + } else { + prefix = "传输失败"; + } + return ApiResponse.error(prefix + ": " + msg); } } diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html index 80467c0..51bb5d8 100644 --- a/src/main/resources/static/index.html +++ b/src/main/resources/static/index.html @@ -24,7 +24,8 @@