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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
<div class="btn-group" role="group">
|
||||
<button type="button" class="btn btn-sm btn-outline-primary" onclick="uploadFiles()">上传</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-primary" onclick="downloadFiles()">下载</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-primary" onclick="transferFiles()">传输到右侧</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-primary" onclick="transferToRight()">传输到右侧</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-primary" onclick="transferToLeft()">传输到左侧</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-danger" onclick="deleteFiles()">删除</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" onclick="showRenameDialog()">重命名</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" onclick="showMkdirDialog()">新建文件夹</button>
|
||||
|
||||
@@ -354,7 +354,7 @@ function handleFileDrop(data, targetPanelId) {
|
||||
const targetPath = panelState[targetPanelId].currentPath;
|
||||
|
||||
if (sourcePanelId === targetPanelId) {
|
||||
updateStatus('同面板内移动功能开发中,请使用「传输到右侧」按钮');
|
||||
updateStatus('同面板内移动功能开发中,请使用「传输到右侧」或「传输到左侧」按钮');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1061,19 +1061,15 @@ function downloadFiles() {
|
||||
});
|
||||
}
|
||||
|
||||
// 传输到对面面板
|
||||
function transferFiles() {
|
||||
const sourcePanelId = getSourcePanelId();
|
||||
const targetPanelId = sourcePanelId === 'left' ? 'right' : 'left';
|
||||
|
||||
// 按方向执行跨面板传输(源面板 -> 目标面板)
|
||||
function doTransfer(sourcePanelId, targetPanelId) {
|
||||
const sourceSessionId = panelState[sourcePanelId].sessionId;
|
||||
const targetSessionId = panelState[targetPanelId].sessionId;
|
||||
const targetPath = panelState[targetPanelId].currentPath;
|
||||
|
||||
const selectedFiles = panelState[sourcePanelId].selectedFiles;
|
||||
|
||||
if (selectedFiles.length === 0) {
|
||||
alert('请先选择要传输的文件');
|
||||
alert('请在' + (sourcePanelId === 'left' ? '左侧' : '右侧') + '面板选择要传输的文件');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1089,7 +1085,7 @@ function transferFiles() {
|
||||
showTransferCountProgress(0, total, '');
|
||||
updateTransferProgress(0, '传输中 (0/' + total + ')');
|
||||
|
||||
selectedFiles.forEach(function(sourcePath, index) {
|
||||
selectedFiles.forEach(function(sourcePath) {
|
||||
$.ajax({
|
||||
url: API_BASE + 'api/files/transfer',
|
||||
method: 'POST',
|
||||
@@ -1139,6 +1135,16 @@ function transferFiles() {
|
||||
updateStatus('正在传输 ' + total + ' 个文件...');
|
||||
}
|
||||
|
||||
// 传输到右侧:左侧面板选中的文件 -> 右侧面板
|
||||
function transferToRight() {
|
||||
doTransfer('left', 'right');
|
||||
}
|
||||
|
||||
// 传输到左侧:右侧面板选中的文件 -> 左侧面板
|
||||
function transferToLeft() {
|
||||
doTransfer('right', 'left');
|
||||
}
|
||||
|
||||
// ========== 文件删除功能(模块06)==========
|
||||
|
||||
// 工具栏删除:删除当前活动面板中选中的文件
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
<div class="btn-group" role="group">
|
||||
<button type="button" class="btn btn-sm btn-outline-primary" onclick="uploadFiles()">上传</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-primary" onclick="downloadFiles()">下载</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-primary" onclick="transferFiles()">传输到右侧</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-primary" onclick="transferToRight()">传输到右侧</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-primary" onclick="transferToLeft()">传输到左侧</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-danger" onclick="deleteFiles()">删除</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" onclick="showRenameDialog()">重命名</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" onclick="showMkdirDialog()">新建文件夹</button>
|
||||
|
||||
Reference in New Issue
Block a user