(req dto.SearchPageWithType)
| 80 | } |
| 81 | |
| 82 | func (u *BackupService) SearchWithPage(req dto.SearchPageWithType) (int64, interface{}, error) { |
| 83 | options := []repo.DBOption{repo.WithOrderDesc("created_at")} |
| 84 | if len(req.Type) != 0 { |
| 85 | options = append(options, repo.WithByType(req.Type)) |
| 86 | } |
| 87 | if len(req.Info) != 0 { |
| 88 | options = append(options, repo.WithByType(req.Info)) |
| 89 | } |
| 90 | count, accounts, err := backupRepo.Page(req.Page, req.PageSize, options...) |
| 91 | if err != nil { |
| 92 | return 0, nil, err |
| 93 | } |
| 94 | var data []dto.BackupInfo |
| 95 | for _, account := range accounts { |
| 96 | var item dto.BackupInfo |
| 97 | if err := copier.Copy(&item, &account); err != nil { |
| 98 | global.LOG.Errorf("copy backup account to dto backup info failed, err: %v", err) |
| 99 | } |
| 100 | if item.Type != constant.Sftp && item.Type != constant.Local { |
| 101 | item.BackupPath = path.Join("/", strings.TrimPrefix(item.BackupPath, "/")) |
| 102 | } |
| 103 | if !item.RememberAuth { |
| 104 | item.AccessKey = "" |
| 105 | item.Credential = "" |
| 106 | if account.Type == constant.Sftp { |
| 107 | varMap := make(map[string]interface{}) |
| 108 | if err := json.Unmarshal([]byte(item.Vars), &varMap); err != nil { |
| 109 | continue |
| 110 | } |
| 111 | delete(varMap, "passPhrase") |
| 112 | itemVars, _ := json.Marshal(varMap) |
| 113 | item.Vars = string(itemVars) |
| 114 | } |
| 115 | } else { |
| 116 | item.AccessKey, _ = encrypt.StringDecryptWithBase64(item.AccessKey) |
| 117 | item.Credential, _ = encrypt.StringDecryptWithBase64(item.Credential) |
| 118 | } |
| 119 | |
| 120 | if account.Type == constant.OneDrive || account.Type == constant.ALIYUN || account.Type == constant.GoogleDrive { |
| 121 | varMap := make(map[string]interface{}) |
| 122 | if err := json.Unmarshal([]byte(item.Vars), &varMap); err != nil { |
| 123 | continue |
| 124 | } |
| 125 | delete(varMap, "refresh_token") |
| 126 | delete(varMap, "drive_id") |
| 127 | itemVars, _ := json.Marshal(varMap) |
| 128 | item.Vars = string(itemVars) |
| 129 | } |
| 130 | data = append(data, item) |
| 131 | } |
| 132 | return count, data, nil |
| 133 | } |
| 134 | |
| 135 | func (u *BackupService) CheckConn(req dto.BackupOperate) dto.BackupCheckRes { |
| 136 | var res dto.BackupCheckRes |
nothing calls this directly
no test coverage detected