From aa6d8a4313228d20a39ab7764b60a35bb0699f09 Mon Sep 17 00:00:00 2001 From: razerbeans Date: Wed, 5 Jan 2011 15:39:55 -0600 Subject: [PATCH] Code cleanup. Successfully working with Cyberduck now. --- lib/boardwalk/control_routes.rb | 2 +- lib/boardwalk/helpers.rb | 2 +- lib/boardwalk/s3_routes.rb | 9 +++------ 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/boardwalk/control_routes.rb b/lib/boardwalk/control_routes.rb index 5b2b852..fa748e9 100644 --- a/lib/boardwalk/control_routes.rb +++ b/lib/boardwalk/control_routes.rb @@ -70,7 +70,7 @@ end tempf = Tempfile.new("#{slot.file_name}") tempf.puts slot.bit.data - send_file(tempf.path, {:disposition => 'attachment', :filename => slot.file_name, :type => slot.bit_type}) + send_file(tempf.path, {:disposition => 'attachment', :filename => slot.file_name, :type => slot.bit_type, :length => slot.bit_size}) tempf.close! status 200 end diff --git a/lib/boardwalk/helpers.rb b/lib/boardwalk/helpers.rb index d000cd5..cc7df73 100644 --- a/lib/boardwalk/helpers.rb +++ b/lib/boardwalk/helpers.rb @@ -14,7 +14,7 @@ def aws_authenticate @amz.sort.each do |k, v| canonical[-1,0] = "x-amz-#{k}:#{v}" end - # puts "Environment info: " + @env.inspect + # puts "\e[1;32mEnvironment info:\e[0m" + @env.inspect @user = User.first(:conditions => {:s3key => key}) if @user and secret != hmac_sha1(@user.s3secret, canonical.map{|v|v.to_s.strip} * "\n") raise BadAuthentication diff --git a/lib/boardwalk/s3_routes.rb b/lib/boardwalk/s3_routes.rb index f39d181..e886166 100644 --- a/lib/boardwalk/s3_routes.rb +++ b/lib/boardwalk/s3_routes.rb @@ -69,8 +69,9 @@ aws_authenticate bucket = @user.buckets.to_enum.find{|b| b.name == params[:captures][0]} slot = bucket.slots.to_enum.find{|s| s.file_name == params[:captures][1]} + # puts "\e[1;32mBit size:\e[0m " + slot.bit_size.to_s aws_only_can_read slot - + since = Time.httpdate(request.env['HTTP_IF_MODIFIED_SINCE']) rescue nil if since && (slot.bit.upload_date) <= since raise NotModified @@ -82,14 +83,10 @@ if request.env['HTTP_IF_NONE_MATCH'] && (slot.md5 == request.env['HTTP_IF_NONE_MATCH']) raise NotModified end - if request.env['HTTP_RANGE'] - raise NotImplemented - end tempf = Tempfile.new("#{slot.file_name}") tempf.puts slot.bit.data - send_file(tempf.path, {:disposition => 'attachment', :filename => slot.file_name, :type => slot.bit_type}) + send_file(tempf.path, {:disposition => 'attachment', :filename => slot.file_name, :type => slot.bit_type, :length => slot.bit_size}) tempf.close! - status 200 end get %r{/([^\/]+)/?} do |e|