Upload workflow improved

This commit is contained in:
Christoph Haas 2016-11-01 09:16:52 +01:00
parent 4ee670e438
commit 10e44d1aaf
3 changed files with 16 additions and 12 deletions

View file

@ -24,37 +24,39 @@ class PackagesController < ApplicationController
end
# POST target of the screenshots upload form.
# Checks upload images and creates a new Screenshot record for it.
# Receives uploaded images. Checks if they are valid. Asks for description.
def upload_image
# Remember the user by the cookie session
create_user_token
@package = Package.find_by!(name: params[:name])
# @images = params[:screenshot][:image]
@images = []
successful_upload_count = 0
# Save the images already if they are valid.
params[:screenshot][:image].each do |img|
new_screenshot = @package.screenshots.new(image: img)
# Check if the image was valid
@images.push new_screenshot
if new_screenshot.valid?
new_screenshot.uploaderhash = session[:token]
new_screenshot.uploaderip = session[:ip]
new_screenshot.version = @package.version
new_screenshot.save
successful_upload_count += 1
# successful_upload_count += 1
Log.log "Screenshot #{new_screenshot.id} uploaded successfully."
else
errors = new_screenshot.errors[:image].join(' and ')
flash['alert'] = "Sorry - the image #{errors}"
# else
# errors = new_screenshot.errors[:image].join(' and ')
# flash['alert'] = "Sorry - the image #{errors}"
end
if successful_upload_count > 0
flash['notice'] = "#{successful_upload_count} #{'screenshot'.pluralize(successful_upload_count)} uploaded successfully."
end
# if successful_upload_count > 0
# flash['notice'] = "#{successful_upload_count} #{'screenshot'.pluralize(successful_upload_count)} uploaded successfully."
# end
end
redirect_to package_path
# redirect_to package_path
end
# Legacy action to upload an image along with metadata.