mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +08:00
FIX: Change max_image_megapixels logic (#25625)
This commit changes `max_image_megapixels` to be used as is without multiplying by 2 to give extra leway. We found in reality this was just causing confusion for admins, especially with the already permissive 40MP default.
This commit is contained in:
parent
fb83058e9d
commit
cf4d92f686
|
@ -4345,7 +4345,7 @@ en:
|
|||
images:
|
||||
too_large: "Sorry, the image you are trying to upload is too big (maximum size is %{max_size_kb}KB), please resize it and try again."
|
||||
too_large_humanized: "Sorry, the image you are trying to upload is too big (maximum size is %{max_size}), please resize it and try again."
|
||||
larger_than_x_megapixels: "Sorry, the image you are trying to upload is too large (maximum dimension is %{max_image_megapixels}-megapixels), please resize it and try again."
|
||||
larger_than_x_megapixels: "Sorry, the image you are trying to upload is too large (maximum dimension is %{max_image_megapixels} megapixels), please resize it and try again."
|
||||
size_not_found: "Sorry, but we couldn't determine the size of the image. Maybe your image is corrupted?"
|
||||
placeholders:
|
||||
too_large: "(image larger than %{max_size_kb}KB)"
|
||||
|
|
|
@ -301,12 +301,12 @@ class UploadCreator
|
|||
@upload.errors.add(:base, I18n.t("upload.empty"))
|
||||
elsif pixels == 0 && @image_info.type.to_s != "svg"
|
||||
@upload.errors.add(:base, I18n.t("upload.images.size_not_found"))
|
||||
elsif max_image_pixels > 0 && pixels >= max_image_pixels * 2
|
||||
elsif max_image_pixels > 0 && pixels >= max_image_pixels
|
||||
@upload.errors.add(
|
||||
:base,
|
||||
I18n.t(
|
||||
"upload.images.larger_than_x_megapixels",
|
||||
max_image_megapixels: SiteSetting.max_image_megapixels * 2,
|
||||
max_image_megapixels: SiteSetting.max_image_megapixels,
|
||||
),
|
||||
)
|
||||
end
|
||||
|
|
|
@ -74,6 +74,7 @@ RSpec.describe Upload do
|
|||
end
|
||||
|
||||
it "can reconstruct dimensions on demand" do
|
||||
SiteSetting.max_image_megapixels = 85
|
||||
upload = UploadCreator.new(huge_image, "image.png").create_for(user_id)
|
||||
|
||||
upload.update_columns(width: nil, height: nil, thumbnail_width: nil, thumbnail_height: nil)
|
||||
|
@ -93,6 +94,7 @@ RSpec.describe Upload do
|
|||
end
|
||||
|
||||
it "dimension calculation returns nil on missing image" do
|
||||
SiteSetting.max_image_megapixels = 85
|
||||
upload = UploadCreator.new(huge_image, "image.png").create_for(user_id)
|
||||
upload.update_columns(width: nil, height: nil, thumbnail_width: nil, thumbnail_height: nil)
|
||||
|
||||
|
@ -107,7 +109,7 @@ RSpec.describe Upload do
|
|||
upload = UploadCreator.new(huge_image, "image.png").create_for(user_id)
|
||||
expect(upload.persisted?).to eq(false)
|
||||
expect(upload.errors.messages[:base].first).to eq(
|
||||
I18n.t("upload.images.larger_than_x_megapixels", max_image_megapixels: 20),
|
||||
I18n.t("upload.images.larger_than_x_megapixels", max_image_megapixels: 10),
|
||||
)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user