commit 489dec586a13a3669e08116b90e020047ff4c9fa
parent 7acde0980722f2fd82cb3713befb26fd4c7e4639
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Wed, 1 Feb 2023 21:44:23 -0800
simplify code
Diffstat:
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -4012,14 +4012,16 @@ func UploadsDownloadHandler(c echo.Context) error {
return nil
}
+ userNbDownloaded := database.UserNbDownloaded(authUser.ID, filename)
+
// Display captcha to new users, or old users if they already downloaded the file.
- if !authUser.AccountOldEnough() || database.UserNbDownloaded(authUser.ID, filename) >= 1 {
+ if !authUser.AccountOldEnough() || userNbDownloaded >= 1 {
// Captcha for bigger files
var data captchaRequiredData
data.CaptchaDescription = "Captcha required"
if !authUser.AccountOldEnough() {
data.CaptchaDescription = fmt.Sprintf("Account that are less than 3 days old must complete the captcha to download files bigger than %s", humanize.Bytes(config.MaxFileSizeBeforeDownload))
- } else if database.UserNbDownloaded(authUser.ID, filename) >= 1 {
+ } else if userNbDownloaded >= 1 {
data.CaptchaDescription = fmt.Sprintf("For the second download onward of a file bigger than %s, you must complete the captcha", humanize.Bytes(config.MaxFileSizeBeforeDownload))
}
data.CaptchaID, data.CaptchaImg = captcha.New()
@@ -4460,14 +4462,16 @@ func FileDropDownloadHandler(c echo.Context) error {
return c.Redirect(http.StatusFound, "/")
}
+ userNbDownloaded := database.UserNbDownloaded(authUser.ID, fileName)
+
// Display captcha to new users, or old users if they already downloaded the file.
- if !authUser.AccountOldEnough() || database.UserNbDownloaded(authUser.ID, fileName) >= 1 {
+ if !authUser.AccountOldEnough() || userNbDownloaded >= 1 {
// Captcha for bigger files
var data captchaRequiredData
data.CaptchaDescription = "Captcha required"
if !authUser.AccountOldEnough() {
data.CaptchaDescription = fmt.Sprintf("Account that are less than 3 days old must complete the captcha to download files bigger than %s", humanize.Bytes(config.MaxFileSizeBeforeDownload))
- } else if database.UserNbDownloaded(authUser.ID, fileName) >= 1 {
+ } else if userNbDownloaded >= 1 {
data.CaptchaDescription = fmt.Sprintf("For the second download onward of a file bigger than %s, you must complete the captcha", humanize.Bytes(config.MaxFileSizeBeforeDownload))
}
data.CaptchaID, data.CaptchaImg = captcha.New()