complete multi-root library path support

This commit is contained in:
ShukeBta
2026-06-26 23:02:07 +08:00
parent 2fbfed3ac9
commit e41105910e
5 changed files with 128 additions and 1 deletions
+20 -1
View File
@@ -31,9 +31,16 @@ func (r *LibraryRepository) CreateWithRoots(ctx context.Context, l *model.Librar
if roots[i].SortOrder == 0 {
roots[i].SortOrder = i
}
enabled := roots[i].Enabled
if err := tx.Create(&roots[i]).Error; err != nil {
return err
}
if !enabled {
if err := tx.Model(&model.LibraryRoot{}).Where("id = ?", roots[i].ID).Update("enabled", false).Error; err != nil {
return err
}
roots[i].Enabled = false
}
}
l.Roots = roots
return nil
@@ -113,7 +120,19 @@ func (r *LibraryRepository) CreateRoot(ctx context.Context, root *model.LibraryR
if !r.hasLibraryRootsTable() {
return nil
}
return r.db.WithContext(ctx).Create(root).Error
enabled := root.Enabled
return r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
if err := tx.Create(root).Error; err != nil {
return err
}
if !enabled {
if err := tx.Model(&model.LibraryRoot{}).Where("id = ?", root.ID).Update("enabled", false).Error; err != nil {
return err
}
root.Enabled = false
}
return nil
})
}
func (r *LibraryRepository) UpdateRoot(ctx context.Context, root *model.LibraryRoot, updates map[string]any) error {