Skip to content

Commit

Permalink
Send gzipped json as download
Browse files Browse the repository at this point in the history
  • Loading branch information
gdpelican committed Jan 12, 2015
1 parent 8013100 commit e24431f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
6 changes: 1 addition & 5 deletions app/controllers/users_controller.rb
Expand Up @@ -142,7 +142,7 @@ def export_profile
end

def download_profile
send_data decompressed_export, type: :json, filename: current_user.export.filename
send_data File.open(current_user.export.path).read, type: :json, filename: current_user.export.filename
end

def export_photos
Expand Down Expand Up @@ -171,10 +171,6 @@ def confirm_email

private

def decompressed_export
ActiveSupport::Gzip.decompress(File.open(current_user.export.path).read)
end

def user_params
params.fetch(:user).permit(
:email,
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Expand Up @@ -300,7 +300,7 @@ def queue_export
end

def perform_export!
export = Tempfile.new([username, '.json'], encoding: 'ascii-8bit')
export = Tempfile.new([username, '.json.gz'], encoding: 'ascii-8bit')
export.write(compressed_export) && export.close
if export.present?
update exporting: false, export: export, exported_at: Time.zone.now
Expand Down
4 changes: 2 additions & 2 deletions app/uploaders/exported_user.rb
Expand Up @@ -9,11 +9,11 @@ def store_dir
end

def extension_white_list
%w(json)
%w(gz)
end

def filename
"#{model.username}_diaspora_data.json"
"#{model.username}_diaspora_data.json.gz"
end

end
3 changes: 2 additions & 1 deletion spec/controllers/users_controller_spec.rb
Expand Up @@ -24,7 +24,8 @@
it "downloads a user's export file" do
@user.perform_export!
get :download_profile
expect(JSON.parse(response.body)['user']['username']).to eq @user.username
parsed = JSON.parse(ActiveSupport::Gzip.decompress(response.body))
expect(parsed['user']['username']).to eq @user.username
end
end

Expand Down

0 comments on commit e24431f

Please sign in to comment.