add meaningful error message on upload [fixes #773]
This commit is contained in:
parent
eae2e74152
commit
dca2fbcefc
|
@ -306,6 +306,10 @@ Discourse.ComposerView = Discourse.View.extend({
|
|||
case 415:
|
||||
bootbox.alert(Em.String.i18n('post.errors.only_images_are_supported'));
|
||||
return;
|
||||
// 422 == there has been an error on the server (mostly due to FastImage)
|
||||
case 422:
|
||||
bootbox.alert(data.jqXHR.responseText);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// otherwise, display a generic error message
|
||||
|
|
|
@ -8,5 +8,11 @@ class UploadsController < ApplicationController
|
|||
return render status: 415, json: failed_json unless file.content_type =~ /^image\/.+/
|
||||
upload = Upload.create_for(current_user.id, file, params[:topic_id])
|
||||
render_serialized(upload, UploadSerializer, root: false)
|
||||
rescue FastImage::ImageFetchFailure
|
||||
render status: 422, text: I18n.t("upload.image.fetch_failure")
|
||||
rescue FastImage::UnknownImageType
|
||||
render status: 422, text: I18n.t("upload.image.unknown_image_type")
|
||||
rescue FastImage::SizeNotFound
|
||||
render status: 422, text: I18n.t("upload.image.size_not_found")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -58,7 +58,6 @@ class Topic < ActiveRecord::Base
|
|||
attr_accessor :posters # TODO: can replace with posters_summary once we remove old list code
|
||||
attr_accessor :topic_list
|
||||
|
||||
|
||||
# The regular order
|
||||
scope :topic_list_order, lambda { order('topics.bumped_at desc') }
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ class Upload < ActiveRecord::Base
|
|||
filesize: File.size(tempfile),
|
||||
original_filename: file.original_filename)
|
||||
|
||||
image_info = FastImage.new(tempfile)
|
||||
image_info = FastImage.new(tempfile, raise_on_failure: true)
|
||||
blob = file.read
|
||||
sha1 = Digest::SHA1.hexdigest(blob)
|
||||
|
||||
|
@ -75,7 +75,7 @@ class Upload < ActiveRecord::Base
|
|||
|
||||
# populate the rest of the info
|
||||
clean_name = Digest::SHA1.hexdigest("#{Time.now.to_s}#{file.original_filename}")[0,16]
|
||||
image_info = FastImage.new(file.tempfile)
|
||||
image_info = FastImage.new(file.tempfile, raise_on_failure: true)
|
||||
clean_name += ".#{image_info.type}"
|
||||
url_root = "/uploads/#{RailsMultisite::ConnectionManagement.current_db}/#{upload.id}"
|
||||
path = "#{Rails.root}/public#{url_root}"
|
||||
|
|
|
@ -900,3 +900,9 @@ en:
|
|||
miscellaneous: "This Agreement constitutes the entire agreement between %{company_short_name} and you concerning the subject matter hereof, and they may only be modified by a written amendment signed by an authorized executive of %{company_short_name}, or by the posting by %{company_short_name} of a revised version. Except to the extent applicable law, if any, provides otherwise, this Agreement, any access to or use of the Website will be governed by the laws of the state of California, U.S.A., excluding its conflict of law provisions, and the proper venue for any disputes arising out of or relating to any of the same will be the state and federal courts located in San Francisco County, California. Except for claims for injunctive or equitable relief or claims regarding intellectual property rights (which may be brought in any competent court without the posting of a bond), any dispute arising under this Agreement shall be finally settled in accordance with the Comprehensive Arbitration Rules of the Judicial Arbitration and Mediation Service, Inc. (“JAMS”) by three arbitrators appointed in accordance with such Rules. The arbitration shall take place in San Francisco, California, in the English language and the arbitral decision may be enforced in any court. The prevailing party in any action or proceeding to enforce this Agreement shall be entitled to costs and attorneys’ fees. If any part of this Agreement is held invalid or unenforceable, that part will be construed to reflect the parties’ original intent, and the remaining portions will remain in full force and effect. A waiver by either party of any term or condition of this Agreement or any breach thereof, in any one instance, will not waive such term or condition or any subsequent breach thereof. You may assign your rights under this Agreement to any party that consents to, and agrees to be bound by, its terms and conditions; %{company_short_name} may assign its rights under this Agreement without condition. This Agreement will be binding upon and will inure to the benefit of the parties, their successors and permitted assigns."
|
||||
|
||||
deleted: 'deleted'
|
||||
|
||||
upload:
|
||||
image:
|
||||
fetch_failure: "Sorry, there has been an error while fetching the image."
|
||||
unknown_image_type: "Sorry, but the file you tried to upload doesn't appear to be an image."
|
||||
size_not_found: "Sorry, but we couldn't determine the size of the image. Maybe your image is corrupted?"
|
|
@ -934,3 +934,9 @@ fr:
|
|||
miscellaneous: "This Agreement constitutes the entire agreement between %{company_short_name} and you concerning the subject matter ereof, and they may only be modified by a written amendment signed by an authorized executive of %{company_short_name}, or by the posting by %{company_short_name} of a revised version. Except to the extent applicable law, if any, provides otherwise, this Agreement, any access to or use of the Website will be governed by the laws of the state of California, U.S.A., excluding its conflict of law provisions, and the proper venue for any disputes arising out of or relating to any of the same will be the state and federal courts located in San Francisco County, California. Except for claims for injunctive or equitable relief or claims regarding intellectual property rights (which may be brought in any competent court without the posting of a bond), any dispute arising under this Agreement shall be finally settled in accordance with the Comprehensive Arbitration Rules of the Judicial Arbitration and Mediation Service, Inc. (“JAMS”) by three arbitrators appointed in accordance with such Rules. The arbitration shall take place in San Francisco, California, in the English language and the arbitral decision may be enforced in any court. The prevailing party in any action or proceeding to enforce this Agreement shall be entitled to costs and attorneys’ fees. If any part of this Agreement is held invalid or unenforceable, that part will be construed to reflect the parties’ original intent, and the remaining portions will remain in full force and effect. A waiver by either party of any term or condition of this Agreement or any breach thereof, in any one instance, will not waive such term or condition or any subsequent breach thereof. You may assign your rights under this Agreement to any party that consents to, and agrees to be bound by, its terms and conditions; %{company_short_name} may assign its rights under this Agreement without condition. This Agreement will be binding upon and will inure to the benefit of the parties, their successors and permitted assigns."
|
||||
|
||||
deleted: 'supprimmé'
|
||||
|
||||
upload:
|
||||
image:
|
||||
fetch_failure: "Désolé, une erreur s'est produite lorsque nous avons essayé de récupérer l'image."
|
||||
unknown_image_type: "Désolé, mais le fichier que vous essayez d'envoyer ne semble pas être une image."
|
||||
size_not_found: "Désolé, mais nous n'avons pas réussit à déterminer la taille de l'image. Peut-être que l'image est corrompue ?"
|
Loading…
Reference in New Issue