diff --git a/app/models/screenshot.rb b/app/models/screenshot.rb index e74d21c..9121090 100644 --- a/app/models/screenshot.rb +++ b/app/models/screenshot.rb @@ -12,6 +12,15 @@ class Screenshot < ActiveRecord::Base url: '/screenshots/:id_partition/:style.png' validates_attachment_content_type :image, :content_type => 'image/png' validates_with AttachmentSizeValidator, :attributes => :image, :less_than => 5.megabytes + validate :validate_image_is_unique + + # Validator that checks if the image has already been uploaded + def validate_image_is_unique + # Look for images with the same checksum / image_fingerprint + if Screenshot.find_by(image_fingerprint: image_fingerprint) + errors.add(:image, "has already been uploaded") + end + end # Return caption for full-screen screenshots. # Takes the description of a screenshot if available.