diff --git a/backend/app/dto/setting.go b/backend/app/dto/setting.go index 4a0d0d3a6..7be17a5d9 100644 --- a/backend/app/dto/setting.go +++ b/backend/app/dto/setting.go @@ -99,9 +99,10 @@ type SnapshotStatus struct { } type SnapshotCreate struct { - ID uint `json:"id"` - From string `json:"from" validate:"required"` - Description string `json:"description" validate:"max=256"` + ID uint `json:"id"` + From string `json:"from" validate:"required"` + DefaultDownload string `json:"defaultDownload" validate:"required"` + Description string `json:"description" validate:"max=256"` } type SnapshotRecover struct { IsNew bool `json:"isNew"` diff --git a/backend/app/model/snapshot.go b/backend/app/model/snapshot.go index 7aaa7e134..09574ca65 100644 --- a/backend/app/model/snapshot.go +++ b/backend/app/model/snapshot.go @@ -2,12 +2,13 @@ package model type Snapshot struct { BaseModel - Name string `json:"name" gorm:"type:varchar(64);not null;unique"` - Description string `json:"description" gorm:"type:varchar(256)"` - From string `json:"from"` - Status string `json:"status" gorm:"type:varchar(64)"` - Message string `json:"message" gorm:"type:varchar(256)"` - Version string `json:"version" gorm:"type:varchar(256)"` + Name string `json:"name" gorm:"type:varchar(64);not null;unique"` + Description string `json:"description" gorm:"type:varchar(256)"` + From string `json:"from"` + DefaultDownload string `json:"defaultDownload" gorm:"type:varchar(64)"` + Status string `json:"status" gorm:"type:varchar(64)"` + Message string `json:"message" gorm:"type:varchar(256)"` + Version string `json:"version" gorm:"type:varchar(256)"` InterruptStep string `json:"interruptStep" gorm:"type:varchar(64)"` RecoverStatus string `json:"recoverStatus" gorm:"type:varchar(64)"` diff --git a/backend/init/migration/migrate.go b/backend/init/migration/migrate.go index a34070037..4ccf3e5c3 100644 --- a/backend/init/migration/migrate.go +++ b/backend/init/migration/migrate.go @@ -69,6 +69,7 @@ func Init() { migrations.UpdateOneDriveToken, migrations.UpdateCronjobSpec, migrations.UpdateBackupRecordPath, + migrations.UpdateSnapshotRecords, }) 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 cf2c69117..65f70932e 100644 --- a/backend/init/migration/migrations/v_1_9.go +++ b/backend/init/migration/migrations/v_1_9.go @@ -415,3 +415,20 @@ var UpdateBackupRecordPath = &gormigrate.Migration{ return nil }, } + +var UpdateSnapshotRecords = &gormigrate.Migration{ + ID: "20240124-update-snapshot-records", + Migrate: func(tx *gorm.DB) error { + if err := tx.AutoMigrate(&model.Snapshot{}); err != nil { + return err + } + var snaps []model.Snapshot + _ = tx.Find(&snaps).Error + for _, snap := range snaps { + _ = tx.Model(&model.Snapshot{}). + Where("id = ?", snap.ID). + Updates(map[string]interface{}{"default_download": snap.From}).Error + } + return nil + }, +} diff --git a/frontend/src/api/interface/setting.ts b/frontend/src/api/interface/setting.ts index 0a5558e38..7f02628bc 100644 --- a/frontend/src/api/interface/setting.ts +++ b/frontend/src/api/interface/setting.ts @@ -90,6 +90,7 @@ export namespace Setting { export interface SnapshotCreate { id: number; from: string; + defaultDownload: string; description: string; } export interface SnapshotImport { diff --git a/frontend/src/views/setting/snapshot/index.vue b/frontend/src/views/setting/snapshot/index.vue index ab9af3720..813b1c420 100644 --- a/frontend/src/views/setting/snapshot/index.vue +++ b/frontend/src/views/setting/snapshot/index.vue @@ -111,9 +111,9 @@ - + + + + + + @@ -180,15 +190,20 @@ const recoverStatusRef = ref(); const importRef = ref(); const isRecordShow = ref(); const backupOptions = ref(); +const accountOptions = ref(); + type FormInstance = InstanceType; const snapRef = ref(); const rules = reactive({ - from: [Rules.requiredSelect], + fromAccounts: [Rules.requiredSelect], + default_download: [Rules.requiredSelect], }); let snapInfo = reactive({ id: 0, from: '', + default_download: '', + fromAccounts: [], description: '', }); @@ -217,6 +232,7 @@ const submitAddSnapshot = (formEl: FormInstance | undefined) => { formEl.validate(async (valid) => { if (!valid) return; loading.value = true; + snapInfo.from = snapInfo.fromAccounts.join(','); await snapshotCreate(snapInfo) .then(() => { loading.value = false; @@ -238,10 +254,27 @@ const loadBackups = async () => { const res = await getBackupList(); backupOptions.value = []; for (const item of res.data) { - if (item.type !== 'LOCAL' && item.id !== 0) { + if (item.id !== 0) { backupOptions.value.push({ label: i18n.global.t('setting.' + item.type), value: item.type }); } } + changeAccount(); +}; + +const changeAccount = async () => { + accountOptions.value = []; + for (const item of backupOptions.value) { + let exit = false; + for (const ac of snapInfo.fromAccounts) { + if (item.value == ac) { + exit = true; + break; + } + } + if (exit) { + accountOptions.value.push(item); + } + } }; const batchDelete = async (row: Setting.SnapshotInfo | null) => {