Private
Public Access
1
0
Files
u-desk/web/src/api/wails-transport.ts
绝尘 3d5a1e5892 优化:工具栏高度对齐+面板统一+远程连接架构+自动恢复预览
- 工具栏:面包屑与右侧组件像素级等高(:deep 34px)、合并重复search handler、统一分隔符样式、删除死代码
- 面板对齐:三面板header统一padding/font-size、文件列表分页固定底部(自定义紧凑)、表头默认隐藏、滚动条统一样式
- 预览区:始终显示空白预览面板、重启自动恢复上次打开文件
- 收藏夹:简化计数显示(共N项)
- 远程连接:ConnectionIndicator自适应UI(无远程显示mini云图标)、ConnectionDialog支持编辑配置、transport抽象层(本地Wails/远程HTTP双模式)、agent后端模块
2026-04-30 22:25:27 +08:00

140 lines
4.6 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 IPC
*/
import type { FsTransport, FileItem, FileOperationResult, DetectTypeResult } from './transport'
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 WailsTransport implements FsTransport {
private checkAvailable(method: string) {
if (!window.go?.main?.App?.[method]) {
throw new Error(`${method} API 不可用`)
}
}
async listDir(path: string): Promise<FileItem[]> {
this.checkAvailable('ListDir')
return transformFileList(await window.go.main.App.ListDir(path))
}
async getFileInfo(path: string): Promise<Record<string, any>> {
this.checkAvailable('GetFileInfo')
return window.go.main.App.GetFileInfo(path)
}
async readFile(path: string): Promise<string> {
this.checkAvailable('ReadFile')
return window.go.main.App.ReadFile(path)
}
async writeFile(path: string, content: string): Promise<void> {
this.checkAvailable('WriteFile')
await window.go.main.App.WriteFile({ path: String(path), content: String(content) })
}
async saveBase64File(path: string, content: string): Promise<void> {
this.checkAvailable('SaveBase64File')
if (!content) throw new Error('无效的 base64 内容')
await window.go.main.App.SaveBase64File({ path: String(path), content })
}
async createFile(dirPath: string, filename: string): Promise<FileOperationResult> {
this.checkAvailable('CreateFile')
const fullPath = dirPath.replace(/\/$/, '') + '/' + filename
return window.go.main.App.CreateFile(fullPath)
}
async createDir(parentPath: string, dirname: string): Promise<FileOperationResult> {
this.checkAvailable('CreateDir')
const fullPath = parentPath.replace(/\/$/, '') + '/' + dirname
return window.go.main.App.CreateDir(fullPath)
}
async deletePath(path: string): Promise<FileOperationResult> {
this.checkAvailable('DeletePath')
return window.go.main.App.DeletePath(path)
}
async renamePath(oldPath: string, newPath: string): Promise<FileOperationResult> {
this.checkAvailable('RenamePath')
return window.go.main.App.RenamePath({ oldPath: String(oldPath), newPath: String(newPath) })
}
async listZipContents(zipPath: string): Promise<FileItem[]> {
this.checkAvailable('ListZipContents')
return transformFileList(await window.go.main.App.ListZipContents(zipPath))
}
async extractFileFromZip(zipPath: string, filePath: string): Promise<string> {
this.checkAvailable('ExtractFileFromZip')
return window.go.main.App.ExtractFileFromZip(zipPath, filePath)
}
async extractFileFromZipToTemp(zipPath: string, filePath: string): Promise<string> {
this.checkAvailable('ExtractFileFromZipToTemp')
return window.go.main.App.ExtractFileFromZipToTemp(zipPath, filePath)
}
async getZipFileInfo(zipPath: string, filePath: string): Promise<FileItem> {
this.checkAvailable('GetZipFileInfo')
return transformFile(await window.go.main.App.GetZipFileInfo(zipPath, filePath))
}
async openPath(path: string): Promise<void> {
this.checkAvailable('OpenPath')
await window.go.main.App.OpenPath(path)
}
async getFileServerURL(): Promise<string> {
this.checkAvailable('GetFileServerURL')
return window.go.main.App.GetFileServerURL()
}
getPreviewToken(): string {
return '' // 本地模式无需 token
}
async resolveShortcut(lnkPath: string): Promise<any> {
this.checkAvailable('ResolveShortcut')
return window.go.main.App.ResolveShortcut(lnkPath)
}
async detectFileTypeByContent(path: string): Promise<DetectTypeResult> {
this.checkAvailable('DetectFileTypeByContent')
const result = await window.go.main.App.DetectFileTypeByContent(path)
return result as unknown as DetectTypeResult
}
async getCommonPaths(): Promise<Record<string, string>> {
this.checkAvailable('GetCommonPaths')
return window.go.main.App.GetCommonPaths()
}
async getRecycleBinEntries(): Promise<any[]> {
this.checkAvailable('GetRecycleBinEntries')
return window.go.main.App.GetRecycleBinEntries()
}
async restoreFromRecycleBin(path: string): Promise<void> {
this.checkAvailable('RestoreFromRecycleBin')
await window.go.main.App.RestoreFromRecycleBin(path)
}
async deletePermanently(path: string): Promise<void> {
this.checkAvailable('DeletePermanently')
await window.go.main.App.DeletePermanently(path)
}
async emptyRecycleBin(): Promise<void> {
this.checkAvailable('EmptyRecycleBin')
await window.go.main.App.EmptyRecycleBin()
}
}