Files
u-desk/frontend/src/api/wails-transport.ts
T
lxy e7a2c5148e 新增: 文件操作增强与预览扩展
- 文件剪贴板复制剪切粘贴,重名自动副本
- SFTP下载到本机与外部文件拖入,目录递归
- 传输进度浮动面板,transfer-progress事件链
- Drawio预览,Excel工作线程,冻结看门狗
- cmd与bat自写batch语法高亮,psm1等映射补齐
2026-09-15 22:26:12 +08:00

141 lines
4.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Wails Transport — 本地文件操作(通过 Wails v3 IPC)
*/
import type { FsTransport, FileItem, FileOperationResult, DetectTypeResult } from './transport'
import { transformFile, transformFileList, joinPath } from './transport'
import {
ListDir, GetFileInfo, ReadFile, WriteFile, SaveBase64File,
CreateFile, CreateDir, DeletePath, RenamePath, CopyPath, MovePath,
ListZipContents, ExtractFileFromZip, ExtractFileFromZipToTemp, GetZipFileInfo,
OpenPath, GetFileServerURL, ResolveShortcut, DetectFileTypeByContent,
GetCommonPaths, GetRecycleBinEntries, RestoreFromRecycleBin,
DeletePermanently, EmptyRecycleBin,
WatchFile, UnwatchFile
} from '../wailsjs/v3-bindings/u-desk/app'
export class WailsTransport implements FsTransport {
async listDir(path: string): Promise<FileItem[]> {
// 蛇形→驼峰转换统一由 system.ts 的 toFileItemList 完成,此处仅类型适配
return transformFileList(await ListDir(path))
}
async getFileInfo(path: string): Promise<Record<string, any>> {
return GetFileInfo(path)
}
async readFile(path: string): Promise<string> {
return ReadFile(path)
}
async writeFile(path: string, content: string): Promise<void> {
await WriteFile({ path: String(path), content: String(content) })
}
async saveBase64File(path: string, content: string): Promise<void> {
if (!content) throw new Error('无效的 base64 内容')
await SaveBase64File({ path: String(path), content })
}
async createFile(dirPath: string, filename: string): Promise<FileOperationResult> {
return CreateFile(joinPath(dirPath, filename))
}
async createDir(parentPath: string, dirname: string): Promise<FileOperationResult> {
return CreateDir(joinPath(parentPath, dirname))
}
async deletePath(path: string): Promise<FileOperationResult> {
return DeletePath(path)
}
async renamePath(oldPath: string, newPath: string): Promise<FileOperationResult> {
return RenamePath({ oldPath: String(oldPath), newPath: String(newPath) })
}
async copyPath(src: string, dst: string): Promise<void> {
await CopyPath(String(src), String(dst))
}
async movePath(src: string, dst: string): Promise<void> {
await MovePath(String(src), String(dst))
}
async downloadToFile(path: string, _localDstDir: string): Promise<string> {
return path // 本地文件无需下载
}
async uploadFromFile(_localPath: string, _remoteDir: string): Promise<void> {
// 本地面板无上传语义(外部文件拖入走 copyPath)
}
async listZipContents(zipPath: string): Promise<FileItem[]> {
return transformFileList(await ListZipContents(zipPath))
}
async extractFileFromZip(zipPath: string, filePath: string): Promise<string> {
return ExtractFileFromZip(zipPath, filePath)
}
async extractFileFromZipToTemp(zipPath: string, filePath: string): Promise<string> {
return ExtractFileFromZipToTemp(zipPath, filePath)
}
async getZipFileInfo(zipPath: string, filePath: string): Promise<FileItem> {
return transformFile(await GetZipFileInfo(zipPath, filePath))
}
async openPath(path: string): Promise<void> {
await OpenPath(path)
}
async getFileServerURL(): Promise<string> {
return GetFileServerURL()
}
getPreviewToken(): string {
return '' // 本地模式无需 token
}
async resolveShortcut(lnkPath: string): Promise<any> {
return ResolveShortcut(lnkPath)
}
async detectFileTypeByContent(path: string): Promise<DetectTypeResult> {
const result = await DetectFileTypeByContent(path)
return result as unknown as DetectTypeResult
}
async getCommonPaths(): Promise<Record<string, string>> {
return GetCommonPaths()
}
async getRecycleBinEntries(): Promise<any[]> {
return GetRecycleBinEntries()
}
async restoreFromRecycleBin(path: string): Promise<void> {
await RestoreFromRecycleBin(path)
}
async deletePermanently(path: string): Promise<void> {
await DeletePermanently(path)
}
async emptyRecycleBin(): Promise<void> {
await EmptyRecycleBin()
}
async downloadForPreview(path: string): Promise<string> {
return path
}
async watchFile(path: string): Promise<void> {
await WatchFile(path)
}
async unwatchFile(): Promise<void> {
await UnwatchFile()
}
}