diff --git a/backend/init/migration/migrate.go b/backend/init/migration/migrate.go index 4ccf3e5c3..faae42bfb 100644 --- a/backend/init/migration/migrate.go +++ b/backend/init/migration/migrate.go @@ -70,6 +70,8 @@ func Init() { migrations.UpdateCronjobSpec, migrations.UpdateBackupRecordPath, migrations.UpdateSnapshotRecords, + + migrations.UpdateWebDavConf, }) if err := m.Migrate(); err != nil { global.LOG.Error(err) diff --git a/backend/init/migration/migrations/v_1_9.go b/backend/init/migration/migrations/v_1_9.go index 551684811..2b78ade00 100644 --- a/backend/init/migration/migrations/v_1_9.go +++ b/backend/init/migration/migrations/v_1_9.go @@ -451,3 +451,29 @@ var UpdateSnapshotRecords = &gormigrate.Migration{ return nil }, } + +var UpdateWebDavConf = &gormigrate.Migration{ + ID: "20240205-update-webdav-conf", + Migrate: func(tx *gorm.DB) error { + var backup model.BackupAccount + _ = tx.Where("type = ?", constant.WebDAV).First(&backup).Error + if backup.ID == 0 { + return nil + } + varMap := make(map[string]interface{}) + if err := json.Unmarshal([]byte(backup.Vars), &varMap); err != nil { + return err + } + delete(varMap, "addressItem") + if port, ok := varMap["port"]; ok { + varMap["address"] = fmt.Sprintf("%s:%v", varMap["address"], port) + delete(varMap, "port") + } + + vars, _ := json.Marshal(varMap) + if err := tx.Model(&model.BackupAccount{}).Where("id = ?", backup.ID).Updates(map[string]interface{}{"vars": string(vars)}).Error; err != nil { + return err + } + return nil + }, +} diff --git a/backend/utils/cloud_storage/client/webdav.go b/backend/utils/cloud_storage/client/webdav.go index 78f4ac633..c1013357c 100644 --- a/backend/utils/cloud_storage/client/webdav.go +++ b/backend/utils/cloud_storage/client/webdav.go @@ -6,6 +6,7 @@ import ( "io" "net/http" "os" + "path" "strings" "github.com/studio-b12/gowebdav" @@ -43,7 +44,7 @@ func NewWebDAVClient(vars map[string]interface{}) (*webDAVClient, error) { } func (s webDAVClient) Upload(src, target string) (bool, error) { - targetFilePath := s.Bucket + "/" + target + targetFilePath := path.Join(s.Bucket, target) srcFile, err := os.Open(src) if err != nil { return false, err @@ -62,7 +63,7 @@ func (s webDAVClient) ListBuckets() ([]interface{}, error) { } func (s webDAVClient) Download(src, target string) (bool, error) { - srcPath := s.Bucket + "/" + src + srcPath := path.Join(s.Bucket, src) info, err := s.client.Stat(srcPath) if err != nil { return false, err @@ -85,30 +86,30 @@ func (s webDAVClient) Download(src, target string) (bool, error) { return true, err } -func (s webDAVClient) Exist(path string) (bool, error) { - if _, err := s.client.Stat(s.Bucket + "/" + path); err != nil { +func (s webDAVClient) Exist(pathItem string) (bool, error) { + if _, err := s.client.Stat(path.Join(s.Bucket, pathItem)); err != nil { return false, err } return true, nil } -func (s webDAVClient) Size(path string) (int64, error) { - file, err := s.client.Stat(s.Bucket + "/" + path) +func (s webDAVClient) Size(pathItem string) (int64, error) { + file, err := s.client.Stat(path.Join(s.Bucket, pathItem)) if err != nil { return 0, err } return file.Size(), nil } -func (s webDAVClient) Delete(filePath string) (bool, error) { - if err := s.client.Remove(s.Bucket + "/" + filePath); err != nil { +func (s webDAVClient) Delete(pathItem string) (bool, error) { + if err := s.client.Remove(path.Join(s.Bucket, pathItem)); err != nil { return false, err } return true, nil } func (s webDAVClient) ListObjects(prefix string) ([]string, error) { - files, err := s.client.ReadDir(s.Bucket + "/" + prefix) + files, err := s.client.ReadDir(path.Join(s.Bucket, prefix)) if err != nil { return nil, err } diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index f1723023e..610d7e488 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -1250,6 +1250,7 @@ const message = { MINIO: 'MINIO', SFTP: 'SFTP', WebDAV: 'WebDAV', + WebDAVAlist: 'WebDAV connect Alist can refer to the official documentation', OneDrive: 'Microsoft OneDrive', isCN: 'Century Internet', isNotCN: 'International Version', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index 93045f82a..e24b077fa 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -1173,6 +1173,7 @@ const message = { MINIO: 'MINIO', SFTP: 'SFTP', WebDAV: 'WebDAV', + WebDAVAlist: 'WebDAV 連接 Alist 可參考官方文檔', OneDrive: '微軟 OneDrive', isCN: '世紀互聯', isNotCN: '國際版', @@ -1183,7 +1184,7 @@ const message = { refreshTime: '令牌刷新時間', refreshStatus: '令牌刷新狀態', codeWarning: '當前授權碼格式錯誤,請重新確認!', - backupDir: '備份路徑', + backupDir: '備份目录', code: '授權碼', codeHelper: '請點擊獲取按鈕,然後登錄 OneDrive 復製跳轉鏈接中 code 後面的內容,粘貼到該輸入框中,具體操作可參考官方文檔。', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 09caba71b..c2c1af438 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -1174,6 +1174,7 @@ const message = { MINIO: 'MINIO', SFTP: 'SFTP', WebDAV: 'WebDAV', + WebDAVAlist: 'WebDAV 连接 Alist 可参考官方文档', OneDrive: '微软 OneDrive', isCN: '世纪互联', isNotCN: '国际版', @@ -1184,7 +1185,7 @@ const message = { refreshTime: '令牌刷新时间', refreshStatus: '令牌刷新状态', codeWarning: '当前授权码格式错误,请重新确认!', - backupDir: '备份路径', + backupDir: '备份目录', code: '授权码', codeHelper: '请点击获取按钮,然后登录 OneDrive 复制跳转链接中 code 后面的内容,粘贴到该输入框中,具体操作可参考官方文档。', diff --git a/frontend/src/views/setting/backup-account/index.vue b/frontend/src/views/setting/backup-account/index.vue index 3a3b7e347..1b8d09ade 100644 --- a/frontend/src/views/setting/backup-account/index.vue +++ b/frontend/src/views/setting/backup-account/index.vue @@ -372,7 +372,7 @@ {{ sftpData.varsJson['port'] }} - + {{ sftpData.bucket }} @@ -408,10 +408,7 @@ {{ webDAVData.varsJson['address'] }} - - {{ webDAVData.varsJson['port'] }} - - + {{ webDAVData.bucket }} diff --git a/frontend/src/views/setting/backup-account/sftp/index.vue b/frontend/src/views/setting/backup-account/sftp/index.vue index cfba068d2..b1a8a3771 100644 --- a/frontend/src/views/setting/backup-account/sftp/index.vue +++ b/frontend/src/views/setting/backup-account/sftp/index.vue @@ -39,7 +39,7 @@ v-model.trim="sftpData.rowData!.credential" /> - + diff --git a/frontend/src/views/setting/backup-account/webdav/index.vue b/frontend/src/views/setting/backup-account/webdav/index.vue index 4e1857616..59fbaabc1 100644 --- a/frontend/src/views/setting/backup-account/webdav/index.vue +++ b/frontend/src/views/setting/backup-account/webdav/index.vue @@ -12,20 +12,21 @@ - - - - - - + + + {{ $t('setting.WebDAVAlist') }} + + {{ $t('firewall.quickJump') }} + + - + @@ -67,7 +68,7 @@