- 文件剪贴板复制剪切粘贴,重名自动副本 - SFTP下载到本机与外部文件拖入,目录递归 - 传输进度浮动面板,transfer-progress事件链 - Drawio预览,Excel工作线程,冻结看门狗 - cmd与bat自写batch语法高亮,psm1等映射补齐
197 lines
5.8 KiB
TypeScript
197 lines
5.8 KiB
TypeScript
/**
|
|
* OSS Transport — 通过 Wails IPC 调用 Go 后端 OSS 客户端
|
|
*/
|
|
|
|
import type {
|
|
FsTransport, FileItem, FileOperationResult, DetectTypeResult,
|
|
} from './transport'
|
|
import { transformFileList, joinPath, probeAlive } from './transport'
|
|
import type { ConnectionProfile } from './connection-manager'
|
|
import {
|
|
OssConnect, OssDisconnect, OssListDir, OssReadFile,
|
|
OssWriteFile, OssGetFileInfo, OssCreateDir, OssCreateFile,
|
|
OssDeletePath, OssRenamePath, OssDownloadToTemp, OssDownloadSiteForPreview,
|
|
OssGetCommonPaths, OssWriteBase64File, OssGetSignedURL,
|
|
} from '@bindings/u-desk/app'
|
|
|
|
export class OssTransport implements FsTransport {
|
|
private profile: ConnectionProfile
|
|
private connID: string | null = null
|
|
|
|
constructor(profile: ConnectionProfile) {
|
|
this.profile = profile
|
|
}
|
|
|
|
async connect(): Promise<string> {
|
|
const result = await OssConnect({
|
|
provider: this.profile.provider || 'qiniu',
|
|
access_key: this.profile.accessKey || '',
|
|
secret_key: this.profile.secretKey || '',
|
|
endpoint: this.profile.endpoint || '',
|
|
})
|
|
this.connID = result
|
|
return result
|
|
}
|
|
|
|
async isAlive(): Promise<boolean> {
|
|
return probeAlive(this.connID, id => OssListDir(id, ''))
|
|
}
|
|
|
|
get sessionId(): string | null { return this.connID }
|
|
|
|
async disconnect(): Promise<void> {
|
|
if (this.connID) {
|
|
try { await OssDisconnect(this.connID) } catch (e) {
|
|
console.warn('[OSS] disconnect error:', e)
|
|
}
|
|
this.connID = null
|
|
}
|
|
}
|
|
|
|
private requireConn(): string {
|
|
if (!this.connID) throw new Error('OSS 未连接')
|
|
return this.connID
|
|
}
|
|
|
|
// ====== 文件列表与信息 ======
|
|
|
|
async listDir(path: string): Promise<FileItem[]> {
|
|
return transformFileList(await OssListDir(this.requireConn(), path))
|
|
}
|
|
|
|
async getFileInfo(path: string): Promise<Record<string, any>> {
|
|
return OssGetFileInfo(this.requireConn(), path)
|
|
}
|
|
|
|
// ====== 文件读写 ======
|
|
|
|
async readFile(path: string): Promise<string> {
|
|
return OssReadFile(this.requireConn(), path)
|
|
}
|
|
|
|
async writeFile(path: string, content: string): Promise<void> {
|
|
await OssWriteFile(this.requireConn(), path, content)
|
|
}
|
|
|
|
async saveBase64File(path: string, content: string): Promise<void> {
|
|
if (!content) throw new Error('无效的 base64 内容')
|
|
await OssWriteBase64File(this.requireConn(), path, content)
|
|
}
|
|
|
|
// ====== 文件操作 ======
|
|
|
|
async createFile(dirPath: string, filename: string): Promise<FileOperationResult> {
|
|
return OssCreateFile(this.requireConn(), joinPath(dirPath, filename))
|
|
}
|
|
|
|
async createDir(parentPath: string, dirname: string): Promise<FileOperationResult> {
|
|
return OssCreateDir(this.requireConn(), joinPath(parentPath, dirname))
|
|
}
|
|
|
|
async deletePath(path: string): Promise<FileOperationResult> {
|
|
return OssDeletePath(this.requireConn(), path)
|
|
}
|
|
|
|
async renamePath(oldPath: string, newPath: string): Promise<FileOperationResult> {
|
|
return OssRenamePath({
|
|
conn_id: this.requireConn(),
|
|
old_path: oldPath,
|
|
new_path: newPath,
|
|
})
|
|
}
|
|
|
|
// ====== 复制/移动/传输(不支持)======
|
|
|
|
async copyPath(_src: string, _dst: string): Promise<void> {
|
|
throw new Error('OSS 面板暂不支持复制/粘贴')
|
|
}
|
|
|
|
async movePath(_src: string, _dst: string): Promise<void> {
|
|
throw new Error('OSS 面板暂不支持剪切/粘贴')
|
|
}
|
|
|
|
async downloadToFile(_path: string, _localDstDir: string): Promise<string> {
|
|
throw new Error('OSS 下载到本机暂未实现')
|
|
}
|
|
|
|
async uploadFromFile(_localPath: string, _remoteDir: string): Promise<void> {
|
|
throw new Error('OSS 上传暂未实现')
|
|
}
|
|
|
|
// ====== ZIP 操作(不支持)======
|
|
|
|
async listZipContents(_zipPath: string): Promise<FileItem[]> {
|
|
throw new Error('ZIP 操作在 OSS 模式暂未实现')
|
|
}
|
|
|
|
async extractFileFromZip(_zipPath: string, _filePath: string): Promise<string> {
|
|
throw new Error('ZIP 操作在 OSS 模式暂未实现')
|
|
}
|
|
|
|
async extractFileFromZipToTemp(_zipPath: string, _filePath: string): Promise<string> {
|
|
throw new Error('ZIP 操作在 OSS 模式暂未实现')
|
|
}
|
|
|
|
async getZipFileInfo(_zipPath: string, _filePath: string): Promise<FileItem> {
|
|
throw new Error('ZIP 操作在 OSS 模式暂未实现')
|
|
}
|
|
|
|
// ====== 系统操作 ======
|
|
|
|
async openPath(_path: string): Promise<void> {
|
|
throw new Error('OSS 模式不支持打开本地路径')
|
|
}
|
|
|
|
async getFileServerURL(): Promise<string> {
|
|
return ''
|
|
}
|
|
|
|
getPreviewToken(): string {
|
|
return ''
|
|
}
|
|
|
|
async resolveShortcut(_lnkPath: string): Promise<any> {
|
|
return null
|
|
}
|
|
|
|
async detectFileTypeByContent(_path: string): Promise<DetectTypeResult> {
|
|
return { extension: '', category: 'unknown', mime_type: '', confidence: 0 }
|
|
}
|
|
|
|
async getCommonPaths(): Promise<Record<string, string>> {
|
|
return OssGetCommonPaths(this.requireConn())
|
|
}
|
|
|
|
// ====== 回收站(无)======
|
|
|
|
async getRecycleBinEntries(): Promise<any[]> {
|
|
return []
|
|
}
|
|
|
|
async restoreFromRecycleBin(_path: string): Promise<void> {}
|
|
|
|
async deletePermanently(_path: string): Promise<void> {}
|
|
|
|
async emptyRecycleBin(): Promise<void> {}
|
|
|
|
// ====== 预览辅助 ======
|
|
|
|
/** 下载远程文件到本地临时目录用于预览(缓存由 Go 后端管理) */
|
|
async downloadForPreview(remotePath: string): Promise<string> {
|
|
return OssDownloadToTemp(this.requireConn(), remotePath)
|
|
}
|
|
|
|
/** 下载 HTML 及其引用的资源到临时目录用于网站预览 */
|
|
async downloadSiteForPreview(remotePath: string): Promise<string> {
|
|
return OssDownloadSiteForPreview(this.requireConn(), remotePath)
|
|
}
|
|
|
|
/** 获取预签名 URL(用于直接预览) */
|
|
async getSignedUrl(key: string): Promise<string> {
|
|
return OssGetSignedURL(this.requireConn(), key)
|
|
}
|
|
|
|
async watchFile(_path: string): Promise<void> { /* OSS 模式不支持文件监听 */ }
|
|
async unwatchFile(): Promise<void> { /* OSS 模式不支持文件监听 */ }
|
|
}
|