abort on dup md5 preprocessing
This commit is contained in:
@@ -148,6 +148,11 @@ class UploadService
|
|||||||
upload.file_size = file.size
|
upload.file_size = file.size
|
||||||
upload.md5 = Digest::MD5.file(file.path).hexdigest
|
upload.md5 = Digest::MD5.file(file.path).hexdigest
|
||||||
|
|
||||||
|
if Post.where(md5: upload.md5).exists?
|
||||||
|
# abort early if this post already exists
|
||||||
|
raise Upload::Error.new("Post with MD5 #{upload.md5} already exists")
|
||||||
|
end
|
||||||
|
|
||||||
Utils.calculate_dimensions(upload, file) do |width, height|
|
Utils.calculate_dimensions(upload, file) do |width, height|
|
||||||
upload.image_width = width
|
upload.image_width = width
|
||||||
upload.image_height = height
|
upload.image_height = height
|
||||||
@@ -398,7 +403,9 @@ class UploadService
|
|||||||
file: replacement.replacement_file
|
file: replacement.replacement_file
|
||||||
)
|
)
|
||||||
upload = preprocessor.start!(CurrentUser.id)
|
upload = preprocessor.start!(CurrentUser.id)
|
||||||
|
return if upload.is_errored?
|
||||||
upload = preprocessor.finish!(upload)
|
upload = preprocessor.finish!(upload)
|
||||||
|
return if upload.is_errored?
|
||||||
md5_changed = upload.md5 != post.md5
|
md5_changed = upload.md5 != post.md5
|
||||||
|
|
||||||
if replacement.replacement_file.present?
|
if replacement.replacement_file.present?
|
||||||
|
|||||||
@@ -114,6 +114,10 @@ class Upload < ApplicationRecord
|
|||||||
status =~ /duplicate/
|
status =~ /duplicate/
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_errored?
|
||||||
|
status =~ /error:/
|
||||||
|
end
|
||||||
|
|
||||||
def duplicate_post_id
|
def duplicate_post_id
|
||||||
@duplicate_post_id ||= status[/duplicate: (\d+)/, 1]
|
@duplicate_post_id ||= status[/duplicate: (\d+)/, 1]
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user