Create MD5 hexdigest for new uploads

This commit is contained in:
Christoph Haas 2020-08-21 19:10:23 +02:00
parent 39f57be413
commit e5f324e726

View file

@ -46,6 +46,7 @@ class PackagesController < ApplicationController
end
params[:file].each do |img|
# Log.log "Uploaded img=#{img.path}"
new_screenshot = @package.screenshots.new(image: img)
# Check if the image was valid
@ -53,6 +54,9 @@ class PackagesController < ApplicationController
new_screenshot.uploaderhash = session.id.to_s
new_screenshot.uploaderip = request.remote_ip
new_screenshot.version = @package.version
# ActiveStorage does not yet create a file checksum automatically.
# Let's do that. It helps detect duplicate uploads later.
new_screenshot.image_fingerprint = Digest::MD5.hexdigest(img.path)
# Can the upload get approved automatically?
if user_signed_in?