Skip to content

Commit dc02049

Browse files
feat(files): Fix Issue with Recycle Bin Failing to Enable (#7636)
1 parent 8e4b162 commit dc02049

File tree

3 files changed

+20
-30
lines changed

3 files changed

+20
-30
lines changed

agent/app/repo/setting.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ type ISettingRepo interface {
2424
DelMonitorBase(timeForDelete time.Time) error
2525
DelMonitorIO(timeForDelete time.Time) error
2626
DelMonitorNet(timeForDelete time.Time) error
27+
UpdateOrCreate(key, value string) error
2728
}
2829

2930
func NewISettingRepo() ISettingRepo {
3031
return &SettingRepo{}
3132
}
3233

33-
func (u *SettingRepo) GetList(opts ...DBOption) ([]model.Setting, error) {
34+
func (s *SettingRepo) GetList(opts ...DBOption) ([]model.Setting, error) {
3435
var settings []model.Setting
3536
db := global.DB.Model(&model.Setting{})
3637
for _, opt := range opts {
@@ -40,15 +41,15 @@ func (u *SettingRepo) GetList(opts ...DBOption) ([]model.Setting, error) {
4041
return settings, err
4142
}
4243

43-
func (u *SettingRepo) Create(key, value string) error {
44+
func (s *SettingRepo) Create(key, value string) error {
4445
setting := &model.Setting{
4546
Key: key,
4647
Value: value,
4748
}
4849
return global.DB.Create(setting).Error
4950
}
5051

51-
func (u *SettingRepo) Get(opts ...DBOption) (model.Setting, error) {
52+
func (s *SettingRepo) Get(opts ...DBOption) (model.Setting, error) {
5253
var settings model.Setting
5354
db := global.DB.Model(&model.Setting{})
5455
for _, opt := range opts {
@@ -58,7 +59,7 @@ func (u *SettingRepo) Get(opts ...DBOption) (model.Setting, error) {
5859
return settings, err
5960
}
6061

61-
func (u *SettingRepo) GetValueByKey(key string) (string, error) {
62+
func (s *SettingRepo) GetValueByKey(key string) (string, error) {
6263
var setting model.Setting
6364
if err := global.DB.Model(&model.Setting{}).Where("key = ?", key).First(&setting).Error; err != nil {
6465
global.LOG.Errorf("load %s from db setting failed, err: %v", key, err)
@@ -67,31 +68,35 @@ func (u *SettingRepo) GetValueByKey(key string) (string, error) {
6768
return setting.Value, nil
6869
}
6970

70-
func (c *SettingRepo) WithByKey(key string) DBOption {
71+
func (s *SettingRepo) WithByKey(key string) DBOption {
7172
return func(g *gorm.DB) *gorm.DB {
7273
return g.Where("key = ?", key)
7374
}
7475
}
7576

76-
func (u *SettingRepo) Update(key, value string) error {
77+
func (s *SettingRepo) Update(key, value string) error {
7778
return global.DB.Model(&model.Setting{}).Where("key = ?", key).Updates(map[string]interface{}{"value": value}).Error
7879
}
7980

80-
func (u *SettingRepo) CreateMonitorBase(model model.MonitorBase) error {
81+
func (s *SettingRepo) CreateMonitorBase(model model.MonitorBase) error {
8182
return global.MonitorDB.Create(&model).Error
8283
}
83-
func (u *SettingRepo) BatchCreateMonitorIO(ioList []model.MonitorIO) error {
84+
func (s *SettingRepo) BatchCreateMonitorIO(ioList []model.MonitorIO) error {
8485
return global.MonitorDB.CreateInBatches(ioList, len(ioList)).Error
8586
}
86-
func (u *SettingRepo) BatchCreateMonitorNet(ioList []model.MonitorNetwork) error {
87+
func (s *SettingRepo) BatchCreateMonitorNet(ioList []model.MonitorNetwork) error {
8788
return global.MonitorDB.CreateInBatches(ioList, len(ioList)).Error
8889
}
89-
func (u *SettingRepo) DelMonitorBase(timeForDelete time.Time) error {
90+
func (s *SettingRepo) DelMonitorBase(timeForDelete time.Time) error {
9091
return global.MonitorDB.Where("created_at < ?", timeForDelete).Delete(&model.MonitorBase{}).Error
9192
}
92-
func (u *SettingRepo) DelMonitorIO(timeForDelete time.Time) error {
93+
func (s *SettingRepo) DelMonitorIO(timeForDelete time.Time) error {
9394
return global.MonitorDB.Where("created_at < ?", timeForDelete).Delete(&model.MonitorIO{}).Error
9495
}
95-
func (u *SettingRepo) DelMonitorNet(timeForDelete time.Time) error {
96+
func (s *SettingRepo) DelMonitorNet(timeForDelete time.Time) error {
9697
return global.MonitorDB.Where("created_at < ?", timeForDelete).Delete(&model.MonitorNetwork{}).Error
9798
}
99+
100+
func (s *SettingRepo) UpdateOrCreate(key, value string) error {
101+
return global.DB.Model(&model.Setting{}).Where("key = ?", key).Assign(model.Setting{Key: key, Value: value}).FirstOrCreate(&model.Setting{}).Error
102+
}

agent/app/service/setting.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,7 @@ func (u *SettingService) GetSettingInfo() (*dto.SettingInfo, error) {
4848
}
4949

5050
func (u *SettingService) Update(key, value string) error {
51-
switch key {
52-
case "AppStoreLastModified":
53-
exist, _ := settingRepo.Get(settingRepo.WithByKey("AppStoreLastModified"))
54-
if exist.ID == 0 {
55-
return settingRepo.Create("AppStoreLastModified", value)
56-
}
57-
case "AppDefaultDomain":
58-
exist, _ := settingRepo.Get(settingRepo.WithByKey("AppDefaultDomain"))
59-
if exist.ID == 0 {
60-
return settingRepo.Create("AppDefaultDomain", value)
61-
}
62-
}
63-
if err := settingRepo.Update(key, value); err != nil {
64-
return err
65-
}
66-
return nil
51+
return settingRepo.UpdateOrCreate(key, value)
6752
}
6853

6954
func (u *SettingService) ReloadConn() error {

frontend/src/views/host/file-management/recycle-bin/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ import { dateFormat, computeSize } from '@/utils/util';
6565
import i18n from '@/lang';
6666
import Delete from './delete/index.vue';
6767
import Reduce from './reduce/index.vue';
68-
import { updateSetting } from '@/api/modules/setting';
6968
import { MsgSuccess } from '@/utils/message';
69+
import { updateAgentSetting } from '@/api/modules/setting';
7070
7171
const open = ref(false);
7272
const req = reactive({
@@ -114,7 +114,7 @@ const getStatus = async () => {
114114
const changeStatus = async () => {
115115
try {
116116
loading.value = true;
117-
await updateSetting({ key: 'FileRecycleBin', value: status.value });
117+
await updateAgentSetting({ key: 'FileRecycleBin', value: status.value });
118118
MsgSuccess(i18n.global.t('file.fileRecycleBinMsg', [i18n.global.t('commons.button.' + status.value)]));
119119
loading.value = false;
120120
} catch (error) {}

0 commit comments

Comments
 (0)