commit a3382daf314b29870e715c37bbdfa5869d52c20a
parent 57a586961caff634b3384618d11b7395360edcb6
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Sat, 7 Jan 2023 22:25:39 -0800
cleanup
Diffstat:
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go
@@ -937,3 +937,12 @@ func TernaryOrZero[T any](predicate bool, a T) T {
var zero T
return Ternary(predicate, a, zero)
}
+
+func InArr[T comparable](needle T, haystack []T) bool {
+ for _, el := range haystack {
+ if el == needle {
+ return true
+ }
+ }
+ return false
+}
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -3010,7 +3010,7 @@ func changeAvatarForm(c echo.Context, data settingsAccountData) error {
}
filetype := http.DetectContentType(fileBytes)
- if filetype != "image/jpeg" && filetype != "image/png" && filetype != "image/gif" && filetype != "image/bmp" && filetype != "image/webp" {
+ if !utils.InArr(filetype, []string{"image/jpeg", "image/png", "image/gif", "image/bmp", "image/webp"}) {
data.ErrorAvatar = "The provided file format is not allowed. Please upload a JPEG, PNG, WEBP, BMP or GIF image"
return c.Render(http.StatusOK, "settings.account", data)
}