From 2c7137258f190e9103b1bd3ce073bfd721da16ca Mon Sep 17 00:00:00 2001 From: Firdavs Date: Wed, 27 Mar 2024 07:39:31 +0300 Subject: [PATCH] [change] Refactor max file size configuration in ConfigInit function --- core/configInit.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/core/configInit.go b/core/configInit.go index 5bd64b9..72512dd 100644 --- a/core/configInit.go +++ b/core/configInit.go @@ -17,8 +17,23 @@ func ConfigInit() { var appConfig config.AppType appConfig.Name = config.App.Name appConfig.Author = config.App.Author - // TODO: Change this to database - appConfig.MaxFileSize = config.App.MaxFileSize + + // Max file size + var maxFileSize *models.Settings + mResult := config.Database.DB.Where("key = ?", "max_file_size").First(&maxFileSize) + if mResult.Error == gorm.ErrRecordNotFound { + config.Database.DB.Create(&models.Settings{ + Key: "max_file_size", + Value: strconv.FormatInt(config.App.MaxFileSize, 10), + }) + appConfig.MaxFileSize = config.App.MaxFileSize + } else { + number, err := strconv.ParseInt(maxFileSize.Value, 10, 64) + if err != nil { + number = int64(config.App.MaxFileSize) + } + appConfig.MaxFileSize = number + } // Application host var host *models.Settings