mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 08:19:15 +08:00
feat(files): Fix Issue with Recycle Bin Failing to Enable (#7636)
This commit is contained in:
parent
8e4b162b59
commit
dc020499b8
@ -24,13 +24,14 @@ type ISettingRepo interface {
|
|||||||
DelMonitorBase(timeForDelete time.Time) error
|
DelMonitorBase(timeForDelete time.Time) error
|
||||||
DelMonitorIO(timeForDelete time.Time) error
|
DelMonitorIO(timeForDelete time.Time) error
|
||||||
DelMonitorNet(timeForDelete time.Time) error
|
DelMonitorNet(timeForDelete time.Time) error
|
||||||
|
UpdateOrCreate(key, value string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewISettingRepo() ISettingRepo {
|
func NewISettingRepo() ISettingRepo {
|
||||||
return &SettingRepo{}
|
return &SettingRepo{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *SettingRepo) GetList(opts ...DBOption) ([]model.Setting, error) {
|
func (s *SettingRepo) GetList(opts ...DBOption) ([]model.Setting, error) {
|
||||||
var settings []model.Setting
|
var settings []model.Setting
|
||||||
db := global.DB.Model(&model.Setting{})
|
db := global.DB.Model(&model.Setting{})
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -40,7 +41,7 @@ func (u *SettingRepo) GetList(opts ...DBOption) ([]model.Setting, error) {
|
|||||||
return settings, err
|
return settings, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *SettingRepo) Create(key, value string) error {
|
func (s *SettingRepo) Create(key, value string) error {
|
||||||
setting := &model.Setting{
|
setting := &model.Setting{
|
||||||
Key: key,
|
Key: key,
|
||||||
Value: value,
|
Value: value,
|
||||||
@ -48,7 +49,7 @@ func (u *SettingRepo) Create(key, value string) error {
|
|||||||
return global.DB.Create(setting).Error
|
return global.DB.Create(setting).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *SettingRepo) Get(opts ...DBOption) (model.Setting, error) {
|
func (s *SettingRepo) Get(opts ...DBOption) (model.Setting, error) {
|
||||||
var settings model.Setting
|
var settings model.Setting
|
||||||
db := global.DB.Model(&model.Setting{})
|
db := global.DB.Model(&model.Setting{})
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -58,7 +59,7 @@ func (u *SettingRepo) Get(opts ...DBOption) (model.Setting, error) {
|
|||||||
return settings, err
|
return settings, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *SettingRepo) GetValueByKey(key string) (string, error) {
|
func (s *SettingRepo) GetValueByKey(key string) (string, error) {
|
||||||
var setting model.Setting
|
var setting model.Setting
|
||||||
if err := global.DB.Model(&model.Setting{}).Where("key = ?", key).First(&setting).Error; err != nil {
|
if err := global.DB.Model(&model.Setting{}).Where("key = ?", key).First(&setting).Error; err != nil {
|
||||||
global.LOG.Errorf("load %s from db setting failed, err: %v", key, err)
|
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) {
|
|||||||
return setting.Value, nil
|
return setting.Value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *SettingRepo) WithByKey(key string) DBOption {
|
func (s *SettingRepo) WithByKey(key string) DBOption {
|
||||||
return func(g *gorm.DB) *gorm.DB {
|
return func(g *gorm.DB) *gorm.DB {
|
||||||
return g.Where("key = ?", key)
|
return g.Where("key = ?", key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *SettingRepo) Update(key, value string) error {
|
func (s *SettingRepo) Update(key, value string) error {
|
||||||
return global.DB.Model(&model.Setting{}).Where("key = ?", key).Updates(map[string]interface{}{"value": value}).Error
|
return global.DB.Model(&model.Setting{}).Where("key = ?", key).Updates(map[string]interface{}{"value": value}).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *SettingRepo) CreateMonitorBase(model model.MonitorBase) error {
|
func (s *SettingRepo) CreateMonitorBase(model model.MonitorBase) error {
|
||||||
return global.MonitorDB.Create(&model).Error
|
return global.MonitorDB.Create(&model).Error
|
||||||
}
|
}
|
||||||
func (u *SettingRepo) BatchCreateMonitorIO(ioList []model.MonitorIO) error {
|
func (s *SettingRepo) BatchCreateMonitorIO(ioList []model.MonitorIO) error {
|
||||||
return global.MonitorDB.CreateInBatches(ioList, len(ioList)).Error
|
return global.MonitorDB.CreateInBatches(ioList, len(ioList)).Error
|
||||||
}
|
}
|
||||||
func (u *SettingRepo) BatchCreateMonitorNet(ioList []model.MonitorNetwork) error {
|
func (s *SettingRepo) BatchCreateMonitorNet(ioList []model.MonitorNetwork) error {
|
||||||
return global.MonitorDB.CreateInBatches(ioList, len(ioList)).Error
|
return global.MonitorDB.CreateInBatches(ioList, len(ioList)).Error
|
||||||
}
|
}
|
||||||
func (u *SettingRepo) DelMonitorBase(timeForDelete time.Time) error {
|
func (s *SettingRepo) DelMonitorBase(timeForDelete time.Time) error {
|
||||||
return global.MonitorDB.Where("created_at < ?", timeForDelete).Delete(&model.MonitorBase{}).Error
|
return global.MonitorDB.Where("created_at < ?", timeForDelete).Delete(&model.MonitorBase{}).Error
|
||||||
}
|
}
|
||||||
func (u *SettingRepo) DelMonitorIO(timeForDelete time.Time) error {
|
func (s *SettingRepo) DelMonitorIO(timeForDelete time.Time) error {
|
||||||
return global.MonitorDB.Where("created_at < ?", timeForDelete).Delete(&model.MonitorIO{}).Error
|
return global.MonitorDB.Where("created_at < ?", timeForDelete).Delete(&model.MonitorIO{}).Error
|
||||||
}
|
}
|
||||||
func (u *SettingRepo) DelMonitorNet(timeForDelete time.Time) error {
|
func (s *SettingRepo) DelMonitorNet(timeForDelete time.Time) error {
|
||||||
return global.MonitorDB.Where("created_at < ?", timeForDelete).Delete(&model.MonitorNetwork{}).Error
|
return global.MonitorDB.Where("created_at < ?", timeForDelete).Delete(&model.MonitorNetwork{}).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SettingRepo) UpdateOrCreate(key, value string) error {
|
||||||
|
return global.DB.Model(&model.Setting{}).Where("key = ?", key).Assign(model.Setting{Key: key, Value: value}).FirstOrCreate(&model.Setting{}).Error
|
||||||
|
}
|
||||||
|
@ -48,22 +48,7 @@ func (u *SettingService) GetSettingInfo() (*dto.SettingInfo, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *SettingService) Update(key, value string) error {
|
func (u *SettingService) Update(key, value string) error {
|
||||||
switch key {
|
return settingRepo.UpdateOrCreate(key, value)
|
||||||
case "AppStoreLastModified":
|
|
||||||
exist, _ := settingRepo.Get(settingRepo.WithByKey("AppStoreLastModified"))
|
|
||||||
if exist.ID == 0 {
|
|
||||||
return settingRepo.Create("AppStoreLastModified", value)
|
|
||||||
}
|
|
||||||
case "AppDefaultDomain":
|
|
||||||
exist, _ := settingRepo.Get(settingRepo.WithByKey("AppDefaultDomain"))
|
|
||||||
if exist.ID == 0 {
|
|
||||||
return settingRepo.Create("AppDefaultDomain", value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := settingRepo.Update(key, value); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *SettingService) ReloadConn() error {
|
func (u *SettingService) ReloadConn() error {
|
||||||
|
@ -65,8 +65,8 @@ import { dateFormat, computeSize } from '@/utils/util';
|
|||||||
import i18n from '@/lang';
|
import i18n from '@/lang';
|
||||||
import Delete from './delete/index.vue';
|
import Delete from './delete/index.vue';
|
||||||
import Reduce from './reduce/index.vue';
|
import Reduce from './reduce/index.vue';
|
||||||
import { updateSetting } from '@/api/modules/setting';
|
|
||||||
import { MsgSuccess } from '@/utils/message';
|
import { MsgSuccess } from '@/utils/message';
|
||||||
|
import { updateAgentSetting } from '@/api/modules/setting';
|
||||||
|
|
||||||
const open = ref(false);
|
const open = ref(false);
|
||||||
const req = reactive({
|
const req = reactive({
|
||||||
@ -114,7 +114,7 @@ const getStatus = async () => {
|
|||||||
const changeStatus = async () => {
|
const changeStatus = async () => {
|
||||||
try {
|
try {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
await updateSetting({ key: 'FileRecycleBin', value: status.value });
|
await updateAgentSetting({ key: 'FileRecycleBin', value: status.value });
|
||||||
MsgSuccess(i18n.global.t('file.fileRecycleBinMsg', [i18n.global.t('commons.button.' + status.value)]));
|
MsgSuccess(i18n.global.t('file.fileRecycleBinMsg', [i18n.global.t('commons.button.' + status.value)]));
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user