diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index 15fe6205..32343f1c 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb @@ -103,8 +103,14 @@ class ContentController < ApplicationController def upload_files image_uploads_hash, content_type, content_id image_uploads_hash.values.each do |image_data| + image_size_kb = File.size(image_data.tempfile.path) / 1000.0 - # todo check user bandwidth + if current_user.upload_bandwidth_kb < image_size_kb + flash[:error] = "At least one of your images failed to upload because you do not have enough upload bandwidth." + next + else + current_user.update(upload_bandwidth_kb: current_user.upload_bandwidth_kb - image_size_kb) + end related_image = ImageUpload.create( user: current_user, diff --git a/app/controllers/image_upload_controller.rb b/app/controllers/image_upload_controller.rb index eee5657c..94e487df 100644 --- a/app/controllers/image_upload_controller.rb +++ b/app/controllers/image_upload_controller.rb @@ -18,13 +18,13 @@ class ImageUploadController < ApplicationController return end - reclaimed_space = image.src_file_size + reclaimed_space_kb = image.src_file_size / 1000.0 # If the user has access to delete the image, go for it result = image.destroy # And credit that space back to their bandwidth - #todo + current_user.update(upload_bandwidth_kb: current_user.upload_bandwidth_kb + reclaimed_space_kb) render json: { success: result }, status: 200 end diff --git a/app/views/content/form/_panel.html.erb b/app/views/content/form/_panel.html.erb index 86385117..c80f03c3 100644 --- a/app/views/content/form/_panel.html.erb +++ b/app/views/content/form/_panel.html.erb @@ -5,7 +5,12 @@ <%= render partial: 'content/form/images/edit_list', locals: { content: content } %>