mirror of https://github.com/cloudreve/Cloudreve
Modify: add unique index for folder & file
parent
b3f13c56bc
commit
ceb25ce1c3
|
@ -10,12 +10,12 @@ import (
|
||||||
type File struct {
|
type File struct {
|
||||||
// 表字段
|
// 表字段
|
||||||
gorm.Model
|
gorm.Model
|
||||||
Name string
|
Name string `gorm:"unique_index:idx_only_one"`
|
||||||
SourceName string
|
SourceName string
|
||||||
UserID uint `gorm:"index:user_id"`
|
UserID uint `gorm:"index:user_id;unique_index:idx_only_one"`
|
||||||
Size uint64
|
Size uint64
|
||||||
PicInfo string
|
PicInfo string
|
||||||
FolderID uint `gorm:"index:folder_id"`
|
FolderID uint `gorm:"index:folder_id;unique_index:idx_only_one"`
|
||||||
PolicyID uint
|
PolicyID uint
|
||||||
Dir string `gorm:"size:65536"`
|
Dir string `gorm:"size:65536"`
|
||||||
|
|
||||||
|
|
|
@ -9,11 +9,11 @@ import (
|
||||||
type Folder struct {
|
type Folder struct {
|
||||||
// 表字段
|
// 表字段
|
||||||
gorm.Model
|
gorm.Model
|
||||||
Name string
|
Name string `gorm:"unique_index:idx_only_one_name"`
|
||||||
ParentID uint `gorm:"index:parent_id"`
|
ParentID uint `gorm:"index:parent_id;unique_index:idx_only_one_name"`
|
||||||
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,9 +140,10 @@ 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,
|
||||||
},
|
},
|
||||||
Position: "/",
|
PositionAbsolute: "/我的文件",
|
||||||
}
|
}
|
||||||
fs := FileSystem{
|
fs := FileSystem{
|
||||||
User: &model.User{
|
User: &model.User{
|
||||||
|
|
|
@ -177,13 +177,11 @@ func (fs *FileSystem) List(ctx context.Context, dirPath string, pathProcessor fu
|
||||||
}
|
}
|
||||||
|
|
||||||
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(filePath)
|
processedPath = pathProcessor(file.Dir)
|
||||||
} else {
|
} else {
|
||||||
processedPath = filePath
|
processedPath = file.Dir
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue