/** * 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 { // 蛇形→驼峰转换统一由 system.ts 的 toFileItemList 完成,此处仅类型适配 return transformFileList(await ListDir(path)) } async getFileInfo(path: string): Promise> { return GetFileInfo(path) } async readFile(path: string): Promise { return ReadFile(path) } async writeFile(path: string, content: string): Promise { await WriteFile({ path: String(path), content: String(content) }) } async saveBase64File(path: string, content: string): Promise { if (!content) throw new Error('无效的 base64 内容') await SaveBase64File({ path: String(path), content }) } async createFile(dirPath: string, filename: string): Promise { return CreateFile(joinPath(dirPath, filename)) } async createDir(parentPath: string, dirname: string): Promise { return CreateDir(joinPath(parentPath, dirname)) } async deletePath(path: string): Promise { return DeletePath(path) } async renamePath(oldPath: string, newPath: string): Promise { return RenamePath({ oldPath: String(oldPath), newPath: String(newPath) }) } async copyPath(src: string, dst: string): Promise { await CopyPath(String(src), String(dst)) } async movePath(src: string, dst: string): Promise { await MovePath(String(src), String(dst)) } async downloadToFile(path: string, _localDstDir: string): Promise { return path // 本地文件无需下载 } async uploadFromFile(_localPath: string, _remoteDir: string): Promise { // 本地面板无上传语义(外部文件拖入走 copyPath) } async listZipContents(zipPath: string): Promise { return transformFileList(await ListZipContents(zipPath)) } async extractFileFromZip(zipPath: string, filePath: string): Promise { return ExtractFileFromZip(zipPath, filePath) } async extractFileFromZipToTemp(zipPath: string, filePath: string): Promise { return ExtractFileFromZipToTemp(zipPath, filePath) } async getZipFileInfo(zipPath: string, filePath: string): Promise { return transformFile(await GetZipFileInfo(zipPath, filePath)) } async openPath(path: string): Promise { await OpenPath(path) } async getFileServerURL(): Promise { return GetFileServerURL() } getPreviewToken(): string { return '' // 本地模式无需 token } async resolveShortcut(lnkPath: string): Promise { return ResolveShortcut(lnkPath) } async detectFileTypeByContent(path: string): Promise { const result = await DetectFileTypeByContent(path) return result as unknown as DetectTypeResult } async getCommonPaths(): Promise> { return GetCommonPaths() } async getRecycleBinEntries(): Promise { return GetRecycleBinEntries() } async restoreFromRecycleBin(path: string): Promise { await RestoreFromRecycleBin(path) } async deletePermanently(path: string): Promise { await DeletePermanently(path) } async emptyRecycleBin(): Promise { await EmptyRecycleBin() } async downloadForPreview(path: string): Promise { return path } async watchFile(path: string): Promise { await WatchFile(path) } async unwatchFile(): Promise { await UnwatchFile() } }