()
| 12 | ) |
| 13 | |
| 14 | func (m *Migrator) migrateNode() error { |
| 15 | m.l.Info("Migrating nodes...") |
| 16 | |
| 17 | var nodes []model.Node |
| 18 | if err := model.DB.Find(&nodes).Error; err != nil { |
| 19 | return fmt.Errorf("failed to list v3 nodes: %w", err) |
| 20 | } |
| 21 | |
| 22 | for _, n := range nodes { |
| 23 | nodeType := node.TypeSlave |
| 24 | nodeStatus := node.StatusSuspended |
| 25 | if n.Type == model.MasterNodeType { |
| 26 | nodeType = node.TypeMaster |
| 27 | } |
| 28 | if n.Status == model.NodeActive { |
| 29 | nodeStatus = node.StatusActive |
| 30 | } |
| 31 | |
| 32 | cap := &boolset.BooleanSet{} |
| 33 | settings := &types.NodeSetting{ |
| 34 | Provider: types.DownloaderProviderAria2, |
| 35 | } |
| 36 | |
| 37 | if n.Aria2Enabled { |
| 38 | boolset.Sets(map[types.NodeCapability]bool{ |
| 39 | types.NodeCapabilityRemoteDownload: true, |
| 40 | }, cap) |
| 41 | |
| 42 | aria2Options := &model.Aria2Option{} |
| 43 | if err := json.Unmarshal([]byte(n.Aria2Options), aria2Options); err != nil { |
| 44 | return fmt.Errorf("failed to unmarshal aria2 options: %w", err) |
| 45 | } |
| 46 | |
| 47 | downloaderOptions := map[string]any{} |
| 48 | if aria2Options.Options != "" { |
| 49 | if err := json.Unmarshal([]byte(aria2Options.Options), &downloaderOptions); err != nil { |
| 50 | return fmt.Errorf("failed to unmarshal aria2 options: %w", err) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | settings.Aria2Setting = &types.Aria2Setting{ |
| 55 | Server: aria2Options.Server, |
| 56 | Token: aria2Options.Token, |
| 57 | Options: downloaderOptions, |
| 58 | TempPath: aria2Options.TempPath, |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | if n.Type == model.MasterNodeType { |
| 63 | boolset.Sets(map[types.NodeCapability]bool{ |
| 64 | types.NodeCapabilityExtractArchive: true, |
| 65 | types.NodeCapabilityCreateArchive: true, |
| 66 | }, cap) |
| 67 | } |
| 68 | |
| 69 | stm := m.v4client.Node.Create(). |
| 70 | SetRawID(int(n.ID)). |
| 71 | SetCreatedAt(formatTime(n.CreatedAt)). |
no test coverage detected