Private
Public Access
1
0

重构:文件系统模块化架构,优化应用启动流程

This commit is contained in:
2026-01-28 00:28:54 +08:00
parent 4a9b25a505
commit 8c577f70e7
123 changed files with 32030 additions and 967 deletions

View File

@@ -71,7 +71,11 @@ export async function writeFile(path: string, content: string): Promise<void> {
if (!window.go?.main?.App?.WriteFile) {
throw new Error('WriteFile API 不可用')
}
await window.go.main.App.WriteFile(path, content)
// 确保传递的是字符串类型
await window.go.main.App.WriteFile({
path: String(path),
content: String(content)
})
}
/**
@@ -84,6 +88,26 @@ export async function deletePath(path: string): Promise<void> {
await window.go.main.App.DeletePath(path)
}
/**
* 创建目录
*/
export async function createDir(path: string): Promise<void> {
if (!window.go?.main?.App?.CreateDir) {
throw new Error('CreateDir API 不可用')
}
await window.go.main.App.CreateDir(path)
}
/**
* 创建文件
*/
export async function createFile(path: string): Promise<void> {
if (!window.go?.main?.App?.CreateFile) {
throw new Error('CreateFile API 不可用')
}
await window.go.main.App.CreateFile(path)
}
/**
* 获取环境变量
*/
@@ -93,3 +117,103 @@ export async function getEnvVars(): Promise<Record<string, string>> {
}
return await window.go.main.App.GetEnvVars()
}
/**
* 列出 zip 文件内容
*/
export async function listZipContents(zipPath: string): Promise<File[]> {
console.log('[API] listZipContents 调用:', zipPath)
if (!window.go?.main?.App?.ListZipContents) {
throw new Error('ListZipContents API 不可用')
}
try {
const result = await window.go.main.App.ListZipContents(zipPath)
console.log('[API] listZipContents 结果:', result?.length || 0, '个文件')
return result
} catch (error) {
console.error('[API] listZipContents 错误:', error)
throw error
}
}
/**
* 从 zip 文件中提取单个文件内容
*/
export async function extractFileFromZip(zipPath: string, filePath: string): Promise<string> {
console.log('[API] extractFileFromZip 调用:', { zipPath, filePath })
if (!window.go?.main?.App?.ExtractFileFromZip) {
throw new Error('ExtractFileFromZip API 不可用')
}
try {
const result = await window.go.main.App.ExtractFileFromZip(zipPath, filePath)
console.log('[API] extractFileFromZip 成功, 内容长度:', result?.length || 0)
return result
} catch (error) {
console.error('[API] extractFileFromZip 错误:', error)
throw error
}
}
/**
* 从 zip 文件中提取单个文件到临时目录
* 返回临时文件的完整路径,适用于图片等二进制文件
*/
export async function extractFileFromZipToTemp(zipPath: string, filePath: string): Promise<string> {
console.log('[API] extractFileFromZipToTemp 调用:', { zipPath, filePath })
if (!window.go?.main?.App?.ExtractFileFromZipToTemp) {
throw new Error('ExtractFileFromZipToTemp API 不可用')
}
try {
const result = await window.go.main.App.ExtractFileFromZipToTemp(zipPath, filePath)
console.log('[API] extractFileFromZipToTemp 成功, 临时文件路径:', result)
return result
} catch (error) {
console.error('[API] extractFileFromZipToTemp 错误:', error)
throw error
}
}
/**
* 获取 zip 文件中特定文件的信息
*/
export async function getZipFileInfo(zipPath: string, filePath: string): Promise<File> {
console.log('[API] getZipFileInfo 调用:', { zipPath, filePath })
if (!window.go?.main?.App?.GetZipFileInfo) {
throw new Error('GetZipFileInfo API 不可用')
}
try {
const result = await window.go.main.App.GetZipFileInfo(zipPath, filePath)
console.log('[API] getZipFileInfo 结果:', result)
return result
} catch (error) {
console.error('[API] getZipFileInfo 错误:', error)
throw error
}
}
/**
* 使用系统默认程序打开文件或目录
*/
export async function openPath(path: string): Promise<void> {
console.log('[API] openPath 调用:', path)
if (!window.go?.main?.App?.OpenPath) {
throw new Error('OpenPath API 不可用')
}
try {
await window.go.main.App.OpenPath(path)
console.log('[API] openPath 成功')
} catch (error) {
console.error('[API] openPath 错误:', error)
throw error
}
}
/**
* 获取本地文件服务器URL
*/
export async function getFileServerURL(): Promise<string> {
if (!window.go?.main?.App?.GetFileServerURL) {
throw new Error('GetFileServerURL API 不可用')
}
return await window.go.main.App.GetFileServerURL()
}