重构: App拆分10域文件+并发安全+结构化日志+依赖升级
This commit is contained in:
+101
@@ -0,0 +1,101 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"u-desk/internal/filesystem"
|
||||
osssvc "u-desk/internal/ossdrv"
|
||||
)
|
||||
|
||||
// ========== OSS 接口 ==========
|
||||
|
||||
func (a *App) ensureOssService() *osssvc.Service {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if a.ossService == nil {
|
||||
a.ossService = osssvc.NewService()
|
||||
}
|
||||
return a.ossService
|
||||
}
|
||||
|
||||
// OssConnect 连接 OSS 存储
|
||||
func (a *App) OssConnect(req OssConnectRequest) (string, error) {
|
||||
if err := a.ensureOssService().GetManager().Connect(req.Provider, req.AccessKey, req.SecretKey, req.Endpoint); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return req.Provider, nil
|
||||
}
|
||||
|
||||
// OssDisconnect 断开 OSS 连接
|
||||
func (a *App) OssDisconnect(connID string) error {
|
||||
osssvc.GetManager().Disconnect(connID)
|
||||
return nil
|
||||
}
|
||||
|
||||
// OssListDir OSS 列出目录
|
||||
func (a *App) OssListDir(connID string, prefix string) ([]map[string]interface{}, error) {
|
||||
return a.ensureOssService().ListDir(connID, prefix)
|
||||
}
|
||||
|
||||
// OssDownloadToTemp OSS 下载到临时文件
|
||||
func (a *App) OssDownloadToTemp(connID string, key string) (string, error) {
|
||||
return a.ensureOssService().DownloadToTemp(connID, key)
|
||||
}
|
||||
|
||||
// OssDownloadSiteForPreview OSS 下载 HTML 及其引用的资源到临时目录
|
||||
func (a *App) OssDownloadSiteForPreview(connID string, key string) (string, error) {
|
||||
return a.ensureOssService().DownloadSiteForPreview(connID, key)
|
||||
}
|
||||
|
||||
// OssDownloadToTempCached 带缓存的 OSS 下载(命中缓存直接返回本地路径)
|
||||
func (a *App) OssDownloadToTempCached(connID string, key string, fileSize int64, modTime string) (string, error) {
|
||||
return a.ensureOssService().DownloadToTempCached(connID, key, fileSize, modTime)
|
||||
}
|
||||
|
||||
// OssReadFile OSS 读取文件
|
||||
func (a *App) OssReadFile(connID string, key string) (string, error) {
|
||||
return a.ensureOssService().ReadFile(connID, key)
|
||||
}
|
||||
|
||||
// OssWriteFile OSS 写入文件
|
||||
func (a *App) OssWriteFile(connID string, key string, content string) error {
|
||||
return a.ensureOssService().WriteFile(connID, key, content)
|
||||
}
|
||||
|
||||
// OssWriteBase64File OSS 写入 base64 编码文件
|
||||
func (a *App) OssWriteBase64File(connID string, key string, base64Content string) error {
|
||||
return a.ensureOssService().WriteBase64File(connID, key, base64Content)
|
||||
}
|
||||
|
||||
// OssGetFileInfo OSS 获取文件信息
|
||||
func (a *App) OssGetFileInfo(connID string, key string) (map[string]interface{}, error) {
|
||||
return a.ensureOssService().GetFileInfo(connID, key)
|
||||
}
|
||||
|
||||
// OssCreateDir OSS 创建目录
|
||||
func (a *App) OssCreateDir(connID string, dirPath string) (*filesystem.FileOperationResult, error) {
|
||||
return a.ensureOssService().CreateDir(connID, dirPath)
|
||||
}
|
||||
|
||||
// OssCreateFile OSS 创建文件
|
||||
func (a *App) OssCreateFile(connID string, filePath string) (*filesystem.FileOperationResult, error) {
|
||||
return a.ensureOssService().CreateFile(connID, filePath)
|
||||
}
|
||||
|
||||
// OssDeletePath OSS 删除
|
||||
func (a *App) OssDeletePath(connID string, key string) (*filesystem.FileOperationResult, error) {
|
||||
return a.ensureOssService().DeletePath(connID, key)
|
||||
}
|
||||
|
||||
// OssRenamePath OSS 重命名
|
||||
func (a *App) OssRenamePath(req OssRenamePathRequest) (*filesystem.FileOperationResult, error) {
|
||||
return a.ensureOssService().RenamePath(req.ConnID, req.OldPath, req.NewPath)
|
||||
}
|
||||
|
||||
// OssGetCommonPaths OSS 获取常用路径
|
||||
func (a *App) OssGetCommonPaths(connID string) (map[string]string, error) {
|
||||
return a.ensureOssService().GetCommonPaths(connID)
|
||||
}
|
||||
|
||||
// OssGetSignedURL OSS 获取预签名 URL
|
||||
func (a *App) OssGetSignedURL(connID string, key string) (string, error) {
|
||||
return a.ensureOssService().GetSignedURL(connID, key)
|
||||
}
|
||||
Reference in New Issue
Block a user