新增: 文件操作增强与预览扩展
- 文件剪贴板复制剪切粘贴,重名自动副本 - SFTP下载到本机与外部文件拖入,目录递归 - 传输进度浮动面板,transfer-progress事件链 - Drawio预览,Excel工作线程,冻结看门狗 - cmd与bat自写batch语法高亮,psm1等映射补齐
This commit is contained in:
@@ -5,22 +5,16 @@
|
||||
import type {
|
||||
FsTransport, FileItem, FileOperationResult, DetectTypeResult,
|
||||
} from './transport'
|
||||
import { transformFileList, joinPath, probeAlive } from './transport'
|
||||
import type { ConnectionProfile } from './connection-manager'
|
||||
import {
|
||||
SftpConnect, SftpDisconnect, SftpListDir, SftpReadFile,
|
||||
SftpWriteFile, SftpGetFileInfo, SftpCreateDir, SftpCreateFile,
|
||||
SftpDeletePath, SftpRenamePath, SftpDownloadToTemp, SftpDownloadSiteForPreview,
|
||||
SftpDownloadToFile, SftpUploadFromFile,
|
||||
SftpGetCommonPaths, SftpWriteBase64File,
|
||||
} from '@bindings/u-desk/app'
|
||||
|
||||
function transformFile(file: any): FileItem {
|
||||
return { ...file, is_dir: file.is_dir, mod_time: file.mod_time }
|
||||
}
|
||||
|
||||
function transformFileList(files: any[]): FileItem[] {
|
||||
return files.map(transformFile)
|
||||
}
|
||||
|
||||
export class SftpTransport implements FsTransport {
|
||||
private profile: ConnectionProfile
|
||||
private connID: string | null = null
|
||||
@@ -42,6 +36,10 @@ export class SftpTransport implements FsTransport {
|
||||
return result
|
||||
}
|
||||
|
||||
async isAlive(): Promise<boolean> {
|
||||
return probeAlive(this.connID, id => SftpGetFileInfo(id, '/'))
|
||||
}
|
||||
|
||||
get sessionId(): string | null { return this.connID }
|
||||
|
||||
async disconnect(): Promise<void> {
|
||||
@@ -90,13 +88,11 @@ export class SftpTransport implements FsTransport {
|
||||
// ====== 文件操作 ======
|
||||
|
||||
async createFile(dirPath: string, filename: string): Promise<FileOperationResult> {
|
||||
const fullPath = dirPath.replace(/\/$/, '') + '/' + filename
|
||||
return SftpCreateFile(this.requireConn(), fullPath)
|
||||
return SftpCreateFile(this.requireConn(), joinPath(dirPath, filename))
|
||||
}
|
||||
|
||||
async createDir(parentPath: string, dirname: string): Promise<FileOperationResult> {
|
||||
const fullPath = parentPath.replace(/\/$/, '') + '/' + dirname
|
||||
return SftpCreateDir(this.requireConn(), fullPath)
|
||||
return SftpCreateDir(this.requireConn(), joinPath(parentPath, dirname))
|
||||
}
|
||||
|
||||
async deletePath(path: string): Promise<FileOperationResult> {
|
||||
@@ -111,6 +107,28 @@ export class SftpTransport implements FsTransport {
|
||||
})
|
||||
}
|
||||
|
||||
// ====== 复制/移动(粘贴仅本地面板支持)======
|
||||
|
||||
async copyPath(_src: string, _dst: string): Promise<void> {
|
||||
throw new Error('SFTP 面板暂不支持粘贴,可使用拖拽上传')
|
||||
}
|
||||
|
||||
async movePath(_src: string, _dst: string): Promise<void> {
|
||||
throw new Error('SFTP 面板暂不支持粘贴,可使用拖拽上传')
|
||||
}
|
||||
|
||||
// ====== 传输 ======
|
||||
|
||||
/** 下载远程文件/目录到用户指定目录(流式无上限,重名自动副本),返回本地落地路径 */
|
||||
async downloadToFile(remotePath: string, localDstDir: string): Promise<string> {
|
||||
return SftpDownloadToFile(this.requireConn(), remotePath, localDstDir)
|
||||
}
|
||||
|
||||
/** 上传本地文件/目录到远程目录(流式,目录递归) */
|
||||
async uploadFromFile(localPath: string, remoteDir: string): Promise<void> {
|
||||
await SftpUploadFromFile(this.requireConn(), localPath, remoteDir)
|
||||
}
|
||||
|
||||
// ====== ZIP 操作(不支持)======
|
||||
|
||||
async listZipContents(_zipPath: string): Promise<FileItem[]> {
|
||||
@@ -179,4 +197,7 @@ export class SftpTransport implements FsTransport {
|
||||
async downloadSiteForPreview(remotePath: string): Promise<string> {
|
||||
return SftpDownloadSiteForPreview(this.requireConn(), remotePath)
|
||||
}
|
||||
|
||||
async watchFile(_path: string): Promise<void> { /* SFTP 模式不支持文件监听 */ }
|
||||
async unwatchFile(): Promise<void> { /* SFTP 模式不支持文件监听 */ }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user