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.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user