-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix: Fix the issue of backup account synchronization failure #7821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,8 +33,8 @@ type IBackupService interface { | |
| Create(backupDto dto.BackupOperate) error | ||
| GetBuckets(backupDto dto.ForBuckets) ([]interface{}, error) | ||
| Update(req dto.BackupOperate) error | ||
| Delete(id uint) error | ||
| RefreshToken(req dto.OperateByID) error | ||
| Delete(name string) error | ||
| RefreshToken(req dto.OperateByName) error | ||
| } | ||
|
|
||
| func NewIBackupService() IBackupService { | ||
|
|
@@ -156,8 +156,8 @@ func (u *BackupService) GetBuckets(req dto.ForBuckets) ([]interface{}, error) { | |
| return client.ListBuckets() | ||
| } | ||
|
|
||
| func (u *BackupService) Delete(id uint) error { | ||
| backup, _ := backupRepo.Get(repo.WithByID(id)) | ||
| func (u *BackupService) Delete(name string) error { | ||
| backup, _ := backupRepo.Get(repo.WithByName(name)) | ||
| if backup.ID == 0 { | ||
| return buserr.New("ErrRecordNotFound") | ||
| } | ||
|
|
@@ -167,21 +167,21 @@ func (u *BackupService) Delete(id uint) error { | |
| if backup.Type == constant.Local { | ||
| return buserr.New("ErrBackupLocal") | ||
| } | ||
| if _, err := req_helper.NewLocalClient(fmt.Sprintf("/api/v2/backups/check/%v", id), http.MethodGet, nil); err != nil { | ||
| if _, err := req_helper.NewLocalClient(fmt.Sprintf("/api/v2/backups/check/%s", name), http.MethodGet, nil); err != nil { | ||
| global.LOG.Errorf("check used of local cronjob failed, err: %v", err) | ||
| return buserr.New("ErrBackupInUsed") | ||
| } | ||
| if err := xpack.CheckBackupUsed(id); err != nil { | ||
| if err := xpack.CheckBackupUsed(name); err != nil { | ||
| global.LOG.Errorf("check used of node cronjob failed, err: %v", err) | ||
| return buserr.New("ErrBackupInUsed") | ||
| } | ||
|
|
||
| go syncAccountToAgent(backup, "delete") | ||
| return backupRepo.Delete(repo.WithByID(id)) | ||
| return backupRepo.Delete(repo.WithByName(name)) | ||
| } | ||
|
|
||
| func (u *BackupService) Update(req dto.BackupOperate) error { | ||
| backup, _ := backupRepo.Get(repo.WithByID(req.ID)) | ||
| backup, _ := backupRepo.Get(repo.WithByName(req.Name)) | ||
| if backup.ID == 0 { | ||
| return buserr.New("ErrRecordNotFound") | ||
| } | ||
|
|
@@ -198,6 +198,7 @@ func (u *BackupService) Update(req dto.BackupOperate) error { | |
| if err := copier.Copy(&newBackup, &req); err != nil { | ||
| return buserr.WithDetail("ErrStructTransform", err.Error(), nil) | ||
| } | ||
| newBackup.ID = backup.ID | ||
| itemAccessKey, err := base64.StdEncoding.DecodeString(newBackup.AccessKey) | ||
| if err != nil { | ||
| return err | ||
|
|
@@ -235,8 +236,8 @@ func (u *BackupService) Update(req dto.BackupOperate) error { | |
| return nil | ||
| } | ||
|
|
||
| func (u *BackupService) RefreshToken(req dto.OperateByID) error { | ||
| backup, _ := backupRepo.Get(repo.WithByID(req.ID)) | ||
| func (u *BackupService) RefreshToken(req dto.OperateByName) error { | ||
| backup, _ := backupRepo.Get(repo.WithByName(req.Name)) | ||
| if backup.ID == 0 { | ||
| return buserr.New("ErrRecordNotFound") | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are no known irregularities, potential issues, or optimization suggestions for the provided code snippet. Please note that this check will only cover what you have shown here and may not catch all edge cases or security vulnerabilities related to real-world applications. Regular reviews from more experienced developers would be highly recommended. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,12 +46,11 @@ export const getFilesFromBackup = (id: number) => { | |
| }; | ||
|
|
||
| // backup-core | ||
| export const refreshToken = (params: { id: number; isPublic: boolean }) => { | ||
| let urlItem = '/core/backups/refresh/token'; | ||
| if (!params.isPublic || !globalStore.isProductPro) { | ||
| urlItem = '/backups/refresh/token'; | ||
| export const refreshToken = (params: { id: number; name: string; isPublic: boolean }) => { | ||
| if (!params.isPublic) { | ||
| return http.post('/backups/refresh/token', { id: params.id }); | ||
| } | ||
| return http.post(urlItem, { id: params.id }); | ||
| return http.post('/core/backups/refresh/token', { name: params.name }); | ||
| }; | ||
| export const getClientInfo = (clientType: string) => { | ||
| return http.get<Backup.ClientInfo>(`/core/backups/client/${clientType}`); | ||
|
|
@@ -65,7 +64,7 @@ export const addBackup = (params: Backup.BackupOperate) => { | |
| request.credential = Base64.encode(request.credential); | ||
| } | ||
| let urlItem = '/core/backups'; | ||
| if (!params.isPublic || !globalStore.isProductPro) { | ||
| if (!params.isPublic) { | ||
| urlItem = '/backups'; | ||
| } | ||
| return http.post<Backup.BackupOperate>(urlItem, request, TimeoutEnum.T_60S); | ||
|
|
@@ -79,17 +78,16 @@ export const editBackup = (params: Backup.BackupOperate) => { | |
| request.credential = Base64.encode(request.credential); | ||
| } | ||
| let urlItem = '/core/backups/update'; | ||
| if (!params.isPublic || !globalStore.isProductPro) { | ||
| if (!params.isPublic) { | ||
| urlItem = '/backups/update'; | ||
| } | ||
| return http.post(urlItem, request); | ||
| }; | ||
| export const deleteBackup = (params: { id: number; isPublic: boolean }) => { | ||
| let urlItem = '/core/backups/del'; | ||
| if (!params.isPublic || !globalStore.isProductPro) { | ||
| urlItem = '/backups/del'; | ||
| export const deleteBackup = (params: { id: number; name: string; isPublic: boolean }) => { | ||
| if (!params.isPublic) { | ||
| return http.post('/backups/del', { id: params.id }); | ||
| } | ||
| return http.post(urlItem, { id: params.id }); | ||
| return http.post('/core/backups/del', { name: params.name }); | ||
| }; | ||
| export const listBucket = (params: Backup.ForBucket) => { | ||
| let request = deepCopy(params) as Backup.BackupOperate; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are no significant changes to the code. The modifications include adding a new |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, but I cannot review and assess code that is not provided. However, general suggestions regarding regular coding practice may include:
For a full assessment, please provide the relevant code snippet.