mirror of https://github.com/cloudreve/Cloudreve
Modify: remove PositionAbsolute scheme in folder
parent
8b3fd8ec66
commit
b3f13c56bc
|
@ -9,11 +9,11 @@ import (
|
||||||
type Folder struct {
|
type Folder struct {
|
||||||
// 表字段
|
// 表字段
|
||||||
gorm.Model
|
gorm.Model
|
||||||
Name string
|
Name string
|
||||||
ParentID uint `gorm:"index:parent_id"`
|
ParentID uint `gorm:"index:parent_id"`
|
||||||
Position string `gorm:"size:65536"`
|
Position string `gorm:"size:65536"`
|
||||||
OwnerID uint `gorm:"index:owner_id"`
|
OwnerID uint `gorm:"index:owner_id"`
|
||||||
PositionAbsolute string `gorm:"size:65536"`
|
//PositionAbsolute string `gorm:"size:65536"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create 创建目录
|
// Create 创建目录
|
||||||
|
|
|
@ -140,10 +140,9 @@ func (user *User) BeforeSave() (err error) {
|
||||||
func (user *User) AfterCreate(tx *gorm.DB) (err error) {
|
func (user *User) AfterCreate(tx *gorm.DB) (err error) {
|
||||||
// 创建用户的默认根目录
|
// 创建用户的默认根目录
|
||||||
defaultFolder := &Folder{
|
defaultFolder := &Folder{
|
||||||
Name: "根目录",
|
Name: "根目录",
|
||||||
Position: ".",
|
Position: ".",
|
||||||
OwnerID: user.ID,
|
OwnerID: user.ID,
|
||||||
PositionAbsolute: "/",
|
|
||||||
}
|
}
|
||||||
tx.Create(defaultFolder)
|
tx.Create(defaultFolder)
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -42,7 +42,7 @@ func (fs *FileSystem) AddFile(ctx context.Context, parent *model.Folder) (*model
|
||||||
Size: file.GetSize(),
|
Size: file.GetSize(),
|
||||||
FolderID: parent.ID,
|
FolderID: parent.ID,
|
||||||
PolicyID: fs.User.Policy.ID,
|
PolicyID: fs.User.Policy.ID,
|
||||||
Dir: parent.PositionAbsolute,
|
//Dir: parent.PositionAbsolute,
|
||||||
}
|
}
|
||||||
_, err := newFile.Create()
|
_, err := newFile.Create()
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ func TestFileSystem_AddFile(t *testing.T) {
|
||||||
Model: gorm.Model{
|
Model: gorm.Model{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
},
|
},
|
||||||
PositionAbsolute: "/我的文件",
|
Position: "/",
|
||||||
}
|
}
|
||||||
fs := FileSystem{
|
fs := FileSystem{
|
||||||
User: &model.User{
|
User: &model.User{
|
||||||
|
|
|
@ -136,9 +136,9 @@ func (fs *FileSystem) ListDeleteFiles(ctx context.Context, paths []string) error
|
||||||
// pathProcessor为最终对象路径的处理钩子。
|
// pathProcessor为最终对象路径的处理钩子。
|
||||||
// 有些情况下(如在分享页面列对象)时,
|
// 有些情况下(如在分享页面列对象)时,
|
||||||
// 路径需要截取掉被分享目录路径之前的部分。
|
// 路径需要截取掉被分享目录路径之前的部分。
|
||||||
func (fs *FileSystem) List(ctx context.Context, path string, pathProcessor func(string) string) ([]Object, error) {
|
func (fs *FileSystem) List(ctx context.Context, dirPath string, pathProcessor func(string) string) ([]Object, error) {
|
||||||
// 获取父目录
|
// 获取父目录
|
||||||
isExist, folder := fs.IsPathExist(path)
|
isExist, folder := fs.IsPathExist(dirPath)
|
||||||
// 不存在时返回空的结果
|
// 不存在时返回空的结果
|
||||||
if !isExist {
|
if !isExist {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
@ -177,11 +177,13 @@ func (fs *FileSystem) List(ctx context.Context, path string, pathProcessor func(
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range childFiles {
|
for _, file := range childFiles {
|
||||||
|
filePath := path.Join(folder.Position, folder.Name, file.Name)
|
||||||
|
|
||||||
if processedPath == "" {
|
if processedPath == "" {
|
||||||
if pathProcessor != nil {
|
if pathProcessor != nil {
|
||||||
processedPath = pathProcessor(file.Dir)
|
processedPath = pathProcessor(filePath)
|
||||||
} else {
|
} else {
|
||||||
processedPath = file.Dir
|
processedPath = filePath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,11 +232,10 @@ func (fs *FileSystem) CreateDirectory(ctx context.Context, fullPath string) erro
|
||||||
|
|
||||||
// 创建目录
|
// 创建目录
|
||||||
newFolder := model.Folder{
|
newFolder := model.Folder{
|
||||||
Name: dir,
|
Name: dir,
|
||||||
ParentID: parent.ID,
|
ParentID: parent.ID,
|
||||||
Position: base,
|
Position: base,
|
||||||
OwnerID: fs.User.ID,
|
OwnerID: fs.User.ID,
|
||||||
PositionAbsolute: fullPath,
|
|
||||||
}
|
}
|
||||||
_, err := newFolder.Create()
|
_, err := newFolder.Create()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue