From 0e8a4eaf2ea23d684628c6025270d69b403afbc7 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Tue, 8 Aug 2023 16:44:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=BF=AB=E7=85=A7=E5=90=8D=E7=A7=B0=E5=8A=A0=E8=BD=BD=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98=20(#1875)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/backup.go | 18 ++++++++++++++---- backend/utils/cloud_storage/client/cos.go | 4 ++-- backend/utils/cloud_storage/client/kodo.go | 4 ++-- backend/utils/cloud_storage/client/minio.go | 4 ++-- backend/utils/cloud_storage/client/onedrive.go | 4 ++-- backend/utils/cloud_storage/client/oss.go | 4 ++-- backend/utils/cloud_storage/client/s3.go | 4 ++-- backend/utils/cloud_storage/client/sftp.go | 4 ++-- .../cloud_storage/cloud_storage_client.go | 2 +- .../views/setting/snapshot/import/index.vue | 3 --- 10 files changed, 29 insertions(+), 22 deletions(-) diff --git a/backend/app/service/backup.go b/backend/app/service/backup.go index 4adfb5aab..34a9b777c 100644 --- a/backend/app/service/backup.go +++ b/backend/app/service/backup.go @@ -37,7 +37,7 @@ type IBackupService interface { BatchDeleteRecord(ids []uint) error NewClient(backup *model.BackupAccount) (cloud_storage.CloudStorageClient, error) - ListFiles(req dto.BackupSearchFile) ([]interface{}, error) + ListFiles(req dto.BackupSearchFile) ([]string, error) MysqlBackup(db dto.CommonBackup) error MysqlRecover(db dto.CommonRecover) error @@ -273,7 +273,7 @@ func (u *BackupService) Update(req dto.BackupOperate) error { return nil } -func (u *BackupService) ListFiles(req dto.BackupSearchFile) ([]interface{}, error) { +func (u *BackupService) ListFiles(req dto.BackupSearchFile) ([]string, error) { backup, err := backupRepo.Get(backupRepo.WithByType(req.Type)) if err != nil { return nil, err @@ -284,9 +284,19 @@ func (u *BackupService) ListFiles(req dto.BackupSearchFile) ([]interface{}, erro } prefix := "system_snapshot" if len(backup.BackupPath) != 0 { - prefix = path.Join("/"+strings.TrimPrefix(backup.BackupPath, "/"), prefix) + prefix = path.Join(strings.TrimPrefix(backup.BackupPath, "/"), prefix) } - return client.ListObjects(prefix) + files, err := client.ListObjects(prefix) + if err != nil { + return nil, err + } + var datas []string + for _, file := range files { + if len(file) != 0 { + datas = append(datas, path.Base(file)) + } + } + return datas, nil } func (u *BackupService) NewClient(backup *model.BackupAccount) (cloud_storage.CloudStorageClient, error) { diff --git a/backend/utils/cloud_storage/client/cos.go b/backend/utils/cloud_storage/client/cos.go index e10aa770c..ba153a5d6 100644 --- a/backend/utils/cloud_storage/client/cos.go +++ b/backend/utils/cloud_storage/client/cos.go @@ -127,7 +127,7 @@ func (cos *cosClient) GetBucket() (string, error) { } } -func (cos cosClient) ListObjects(prefix string) ([]interface{}, error) { +func (cos cosClient) ListObjects(prefix string) ([]string, error) { client, err := cos.newClientWithBucket() if err != nil { return nil, err @@ -137,7 +137,7 @@ func (cos cosClient) ListObjects(prefix string) ([]interface{}, error) { return nil, err } - var result []interface{} + var result []string for _, item := range datas.Contents { result = append(result, item.Key) } diff --git a/backend/utils/cloud_storage/client/kodo.go b/backend/utils/cloud_storage/client/kodo.go index 599404b7d..872d90af1 100644 --- a/backend/utils/cloud_storage/client/kodo.go +++ b/backend/utils/cloud_storage/client/kodo.go @@ -119,13 +119,13 @@ func (kodo *kodoClient) GetBucket() (string, error) { } } -func (kodo kodoClient) ListObjects(prefix string) ([]interface{}, error) { +func (kodo kodoClient) ListObjects(prefix string) ([]string, error) { bucket, err := kodo.GetBucket() if err != nil { return nil, constant.ErrInvalidParams } - var result []interface{} + var result []string marker := "" for { entries, _, nextMarker, hashNext, err := kodo.client.ListFiles(bucket, prefix, "", marker, 1000) diff --git a/backend/utils/cloud_storage/client/minio.go b/backend/utils/cloud_storage/client/minio.go index dacf4ef76..6264507e7 100644 --- a/backend/utils/cloud_storage/client/minio.go +++ b/backend/utils/cloud_storage/client/minio.go @@ -164,7 +164,7 @@ func (minIo *minIoClient) GetBucket() (string, error) { } } -func (minIo minIoClient) ListObjects(prefix string) ([]interface{}, error) { +func (minIo minIoClient) ListObjects(prefix string) ([]string, error) { bucket, err := minIo.GetBucket() if err != nil { return nil, constant.ErrInvalidParams @@ -174,7 +174,7 @@ func (minIo minIoClient) ListObjects(prefix string) ([]interface{}, error) { Prefix: prefix, } - var result []interface{} + var result []string for object := range minIo.client.ListObjects(context.Background(), bucket, opts) { if object.Err != nil { continue diff --git a/backend/utils/cloud_storage/client/onedrive.go b/backend/utils/cloud_storage/client/onedrive.go index 110ff0230..f86d1e810 100644 --- a/backend/utils/cloud_storage/client/onedrive.go +++ b/backend/utils/cloud_storage/client/onedrive.go @@ -196,7 +196,7 @@ func (onedrive oneDriveClient) Download(src, target string) (bool, error) { return true, nil } -func (onedrive *oneDriveClient) ListObjects(prefix string) ([]interface{}, error) { +func (onedrive *oneDriveClient) ListObjects(prefix string) ([]string, error) { prefix = "/" + strings.TrimPrefix(prefix, "/") folderID, err := onedrive.loadIDByPath(prefix) if err != nil { @@ -212,7 +212,7 @@ func (onedrive *oneDriveClient) ListObjects(prefix string) ([]interface{}, error return nil, fmt.Errorf("do request for list failed, err: %v", err) } - var itemList []interface{} + var itemList []string for _, item := range driveItems.DriveItems { itemList = append(itemList, item.Name) } diff --git a/backend/utils/cloud_storage/client/oss.go b/backend/utils/cloud_storage/client/oss.go index 852fc400f..b9116e950 100644 --- a/backend/utils/cloud_storage/client/oss.go +++ b/backend/utils/cloud_storage/client/oss.go @@ -116,7 +116,7 @@ func (oss *ossClient) GetBucket() (*osssdk.Bucket, error) { } } -func (oss *ossClient) ListObjects(prefix string) ([]interface{}, error) { +func (oss *ossClient) ListObjects(prefix string) ([]string, error) { bucket, err := oss.GetBucket() if err != nil { return nil, constant.ErrInvalidParams @@ -125,7 +125,7 @@ func (oss *ossClient) ListObjects(prefix string) ([]interface{}, error) { if err != nil { return nil, err } - var result []interface{} + var result []string for _, obj := range lor.Objects { result = append(result, obj.Key) } diff --git a/backend/utils/cloud_storage/client/s3.go b/backend/utils/cloud_storage/client/s3.go index ea1605d42..a6bce842c 100644 --- a/backend/utils/cloud_storage/client/s3.go +++ b/backend/utils/cloud_storage/client/s3.go @@ -184,13 +184,13 @@ func (s3C *s3Client) getBucket() (string, error) { } } -func (s3C *s3Client) ListObjects(prefix string) ([]interface{}, error) { +func (s3C *s3Client) ListObjects(prefix string) ([]string, error) { bucket, err := s3C.getBucket() if err != nil { return nil, constant.ErrInvalidParams } svc := s3.New(&s3C.Sess) - var result []interface{} + var result []string if err := svc.ListObjectsPages(&s3.ListObjectsInput{ Bucket: &bucket, Prefix: &prefix, diff --git a/backend/utils/cloud_storage/client/sftp.go b/backend/utils/cloud_storage/client/sftp.go index 3a8232306..9c8b75507 100644 --- a/backend/utils/cloud_storage/client/sftp.go +++ b/backend/utils/cloud_storage/client/sftp.go @@ -218,7 +218,7 @@ func (s sftpClient) getBucket() (string, error) { } } -func (s sftpClient) ListObjects(prefix string) ([]interface{}, error) { +func (s sftpClient) ListObjects(prefix string) ([]string, error) { bucket, err := s.getBucket() if err != nil { return nil, err @@ -236,7 +236,7 @@ func (s sftpClient) ListObjects(prefix string) ([]interface{}, error) { if err != nil { return nil, err } - var result []interface{} + var result []string for _, file := range files { result = append(result, file.Name()) } diff --git a/backend/utils/cloud_storage/cloud_storage_client.go b/backend/utils/cloud_storage/cloud_storage_client.go index 0abbc4d50..d1bd6ddff 100644 --- a/backend/utils/cloud_storage/cloud_storage_client.go +++ b/backend/utils/cloud_storage/cloud_storage_client.go @@ -7,7 +7,7 @@ import ( type CloudStorageClient interface { ListBuckets() ([]interface{}, error) - ListObjects(prefix string) ([]interface{}, error) + ListObjects(prefix string) ([]string, error) Exist(path string) (bool, error) Delete(path string) (bool, error) Upload(src, target string) (bool, error) diff --git a/frontend/src/views/setting/snapshot/import/index.vue b/frontend/src/views/setting/snapshot/import/index.vue index fbd409c27..c6d202247 100644 --- a/frontend/src/views/setting/snapshot/import/index.vue +++ b/frontend/src/views/setting/snapshot/import/index.vue @@ -113,9 +113,6 @@ const loadBackups = async () => { const loadFiles = async () => { const res = await getFilesFromBackup(form.from); fileNames.value = res.data || []; - for (let i = 0; i < fileNames.value.length; i++) { - fileNames.value[i] = fileNames.value[i].replaceAll('system_snapshot/', ''); - } }; defineExpose({