mirror of
https://github.com/indentlabs/notebook.git
synced 2025-10-26 11:19:22 +00:00
Subtract account bandwidth on upload, refund on delete
This commit is contained in:
parent
565d5b9db8
commit
96e0a60ea9
@ -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,
|
||||
|
||||
@ -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
|
||||
|
||||
@ -5,7 +5,12 @@
|
||||
<%= render partial: 'content/form/images/edit_list', locals: { content: content } %>
|
||||
</div>
|
||||
<div>
|
||||
<h5>Upload more images</h5>
|
||||
<h5>
|
||||
Upload more images
|
||||
<small class="grey-text">
|
||||
You have <%= Filesize.from("#{current_user.upload_bandwidth_kb}KB").pretty %> of bandwidth remaining.
|
||||
</small>
|
||||
</h5>
|
||||
</div>
|
||||
<div>
|
||||
<%= render partial: 'content/form/images/upload', locals: { f: f, content: content } %>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user