1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-02-12 19:40:06 +08:00

fix: fix the issue of abnormal display of backup account size (#7833)

This commit is contained in:
ssongliu 2025-02-10 11:18:32 +08:00 committed by GitHub
parent 8c2bb231c6
commit 364edbe2ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 8 deletions

View File

@ -166,13 +166,29 @@ func (u *BackupRepo) GetRecord(opts ...DBOption) (*model.BackupRecord, error) {
func (u *BackupRepo) SyncAll(data []model.BackupAccount) error {
tx := global.DB.Begin()
if err := tx.Where("is_public = ?", 1).Delete(&model.BackupAccount{}).Error; err != nil {
tx.Rollback()
return err
var oldAccounts []model.BackupAccount
_ = tx.Where("is_public = ?", 1).Find(&oldAccounts).Error
oldAccountMap := make(map[string]uint)
for _, item := range oldAccounts {
oldAccountMap[item.Name] = item.ID
}
if err := tx.Model(model.BackupAccount{}).Save(&data).Error; err != nil {
tx.Rollback()
return err
for _, item := range data {
if val, ok := oldAccountMap[item.Name]; ok {
item.ID = val
delete(oldAccountMap, item.Name)
} else {
item.ID = 0
}
if err := tx.Model(model.BackupAccount{}).Where("id = ?", item.ID).Save(&item).Error; err != nil {
tx.Rollback()
return err
}
}
for _, val := range oldAccountMap {
if err := tx.Where("id = ?", val).Delete(&model.BackupAccount{}).Error; err != nil {
tx.Rollback()
return err
}
}
tx.Commit()
return nil

View File

@ -101,7 +101,7 @@ var InitSetting = &gormigrate.Migration{
return err
}
if err := tx.Create(&model.Setting{Key: "EncryptKey", Value: common.RandStr(16)}).Error; err != nil {
if err := tx.Create(&model.Setting{Key: "EncryptKey", Value: global.CONF.Base.EncryptKey}).Error; err != nil {
return err
}
if err := tx.Create(&model.Setting{Key: "SystemIP", Value: ""}).Error; err != nil {

View File

@ -1,5 +1,5 @@
<template>
<div>
<div v-loading="loading">
<LayoutContent :title="$t('setting.backupAccount')">
<template #leftToolBar>
<el-button type="primary" @click="onOpenDialog('create')">