Доработайте публикацию и сверку вложений по итогам ревью
This commit is contained in:
@@ -16,6 +16,11 @@ import (
|
||||
const MaxUploadBytes int64 = 10 * 1024 * 1024
|
||||
const MaxImagePixels int64 = 40_000_000
|
||||
|
||||
var imageFormats = map[string]string{
|
||||
"image/png": "png",
|
||||
"image/jpeg": "jpeg",
|
||||
}
|
||||
|
||||
func ValidateFilename(name string) error {
|
||||
if !utf8.ValidString(name) || strings.TrimSpace(name) == "" || utf8.RuneCountInString(name) > 255 {
|
||||
return apperr.Invalid("filename must contain 1-255 characters")
|
||||
@@ -37,7 +42,7 @@ func ValidateImage(r io.Reader, mime string, maxPixels int64) error {
|
||||
if err != nil {
|
||||
return apperr.Wrap(apperr.KindUnsupportedMedia, "invalid image", err)
|
||||
}
|
||||
if (format != "png" && format != "jpeg") || "image/"+format != mime {
|
||||
if expectedFormat, accepted := imageFormats[mime]; !accepted || format != expectedFormat {
|
||||
return apperr.UnsupportedMedia("image does not match Content-Type")
|
||||
}
|
||||
if cfg.Width <= 0 || cfg.Height <= 0 || int64(cfg.Width) > maxPixels/int64(cfg.Height) {
|
||||
|
||||
Reference in New Issue
Block a user