refactor(vfs): 重构VFS模块,拆分数据访问逻辑与路径解析逻辑

将原先的 `vfs.go` 文件中的功能进行拆分,创建了独立的 DAO 层文件 `vfs_dao.go`
和路径处理文件 `vfs_path.go`,以提升代码结构清晰度和可维护性。

- 将数据库操作相关方法迁移至 `VfsDAO` 结构体中
- 新增 `vfs_dao.go` 文件用于管理底层数据访问对象
- 新增 `vfs_path.go` 文件专门处理路径解析逻辑
- 移除了原 `vfs.go` 中的数据库初始化、用户及节点操作等冗余代码
This commit is contained in:
zzy
2025-09-29 00:42:45 +08:00
parent 429a863b76
commit 35e79e54f1
13 changed files with 1106 additions and 1005 deletions

View File

@ -4,27 +4,28 @@ import (
"log"
"os"
"path/filepath"
"sync"
"git.zzyxyz.com/zzy/zzyxyz_go_api/internal/vfs/models"
vfs_service "git.zzyxyz.com/zzy/zzyxyz_go_api/internal/vfs/services"
"github.com/casbin/casbin/v2"
"github.com/casbin/casbin/v2/model"
fileadapter "github.com/casbin/casbin/v2/persist/file-adapter"
)
type VfsImpl struct {
vfs *models.Vfs
enfocer *casbin.Enforcer
config VFSConfig
proxyTable []*ProxyEntry // 动态代理表
proxyMutex sync.RWMutex // 保护代理表的读写锁
Core *vfs_service.VfsCoreService
Proxy *vfs_service.ProxyService
User *vfs_service.UserService
DAO *models.VfsDAO
Enfocer *casbin.Enforcer
Config VFSConfig
}
// 在NewVfsHandler中注册中间件
func NewVfsHandler(config *Config) (*VfsImpl, error) {
var err error
vfs, err := models.NewVfs(config.VFS.DbPath)
dao, err := models.NewVfsDAO(config.VFS.DbPath)
if err != nil {
return nil, err
}
@ -67,11 +68,12 @@ func NewVfsHandler(config *Config) (*VfsImpl, error) {
log.Printf("Register Token: %s", config.VFS.RegisterToken)
impl := &VfsImpl{
vfs: vfs,
enfocer: e,
config: config.VFS,
proxyTable: make([]*ProxyEntry, 0),
proxyMutex: sync.RWMutex{},
Core: vfs_service.NewVfsCoreService(dao),
Proxy: vfs_service.NewProxyService(),
User: vfs_service.NewUserService(dao, e),
DAO: dao,
Enfocer: e,
Config: config.VFS,
}
// 注册中间件