dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit ad60c48ff27ed659e75113d1cbe8c0bb76868489
parent 0b374e952b9dc410caac1a23b299163c678397a0
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Thu, 12 Jan 2023 14:02:42 -0800

cleanup hardcoded values

Diffstat:
Mpkg/config/config.go | 10++++++++--
Mpkg/web/handlers/handlers.go | 8++++----
2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/pkg/config/config.go b/pkg/config/config.go @@ -15,8 +15,14 @@ import ( const ( DbFileName = "dkf.db" AppDirName = ".dkf" - MaxUserFileUploadSize = 30 << 20 - MaxUserTotalUploadSize = 100 << 20 + MaxUserFileUploadSize = 30 << 20 // 30 MB + MaxUserTotalUploadSize = 100 << 20 // 100 MB + MaxAvatarFormSize = 1 << 20 // 1 MB + MaxAvatarSize = 300 << 10 // 300 KB + + // MaxFileSizeBeforeDownload files that are bigger than this limit will trigger + // a file download instead of simple in-browser rendering + MaxFileSizeBeforeDownload = 1 << 20 // 1 MB ) // DefaultMasterKey Should be overwritten using ldflags diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -2833,7 +2833,7 @@ func changeAvatarForm(c echo.Context, data settingsAccountData) error { data.ErrorAvatar = hutils.AccountTooYoungErr.Error() return c.Render(http.StatusOK, "settings.account", data) } - if err := c.Request().ParseMultipartForm(1024 * 1024 /* 1 MB */); err != nil { + if err := c.Request().ParseMultipartForm(config.MaxAvatarFormSize); err != nil { data.ErrorAvatar = err.Error() return c.Render(http.StatusOK, "settings.account", data) } @@ -2843,8 +2843,8 @@ func changeAvatarForm(c echo.Context, data settingsAccountData) error { return c.Render(http.StatusOK, "settings.account", data) } defer file.Close() - if handler.Size > 300<<10 { - data.ErrorAvatar = "The maximum file size for avatars is 300 KB" + if handler.Size > config.MaxAvatarSize { + data.ErrorAvatar = fmt.Sprintf("The maximum file size for avatars is %s", humanize.Bytes(config.MaxAvatarSize)) return c.Render(http.StatusOK, "settings.account", data) } fileBytes, err := ioutil.ReadAll(file) @@ -3795,7 +3795,7 @@ func UploadsDownloadHandler(c echo.Context) error { return c.Redirect(http.StatusFound, "/") } - if file.FileSize < 1<<20 { + if file.FileSize < config.MaxFileSizeBeforeDownload { fi, decFileBytes, err := file.GetContent() if err != nil || fi.IsDir() { return echo.NotFoundHandler(c)