diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 407b85330..df4519f65 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -5,6 +5,7 @@ class UsersController < ApplicationController require File.expand_path('../../../lib/diaspora/ostatus_builder', __FILE__) require File.expand_path('../../../lib/diaspora/exporter', __FILE__) + require File.expand_path('../../../lib/collect_user_photos', __FILE__) before_filter :authenticate_user!, :except => [:new, :create, :public] @@ -62,6 +63,11 @@ class UsersController < ApplicationController send_data exporter.execute(current_user), :filename => "#{current_user.username}_diaspora_data.xml", :type => :xml end + def export_photos + tar_path = PhotoMover::move_photos(current_user) + send_data( File.open(tar_path).read, :filename => "#{current_user.id}.tar" ) + end + private def prep_image_url(params) url = APP_CONFIG[:pod_url].chop if APP_CONFIG[:pod_url][-1,1] == '/' diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index cd8deb068..78076e789 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -26,7 +26,8 @@ = render 'users/profile' #account.settings_pane - = link_to "download my stuff", users_export_path, :class => "button" + = link_to "download my xml", users_export_path, :class => "button" + = link_to "download my photos", users_export_photos_path, :class => "button" #services.settings_pane = render 'users/services' diff --git a/config/environments/development.rb b/config/environments/development.rb index ee08a058f..80022947e 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -24,16 +24,4 @@ Diaspora::Application.configure do config.active_support.deprecation = :log config.middleware.use MongoMapper::ClearDevMemory #config.threadsafe! - - config.action_mailer.delivery_method = :smtp - config.action_mailer.default_url_options = {:host => 'pivots.joindiaspora.com'} - config.action_mailer.smtp_settings = { - :address => 'smtp.gmail.com', - :port => 587, - :domain => 'mail.joindiaspora.com', - :authentication => 'plain', - :user_name => 'diaspora-pivots@joindiaspora.com', - :password => "xy289|]G+R*-kA", - :enable_starttls_auto => true - } end diff --git a/config/initializers/mailer_config.rb b/config/initializers/mailer_config.rb new file mode 100644 index 000000000..73928f740 --- /dev/null +++ b/config/initializers/mailer_config.rb @@ -0,0 +1,17 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +Diaspora::Application.configure do + config.action_mailer.delivery_method = :smtp + config.action_mailer.default_url_options = {:host => APP_CONFIG[:terse_pod_url]} + config.action_mailer.smtp_settings = { + :address => APP_CONFIG[:smtp_address], + :port => APP_CONFIG[:smtp_port], + :domain => APP_CONFIG[:smtp_domain], + :authentication => APP_CONFIG[:smtp_authentication], + :user_name => APP_CONFIG[:smtp_username], + :password => APP_CONFIG[:smtp_password], + :enable_starttls_auto => true + } +end diff --git a/config/routes.rb b/config/routes.rb index 802ebd260..a51670449 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -15,6 +15,7 @@ Diaspora::Application.routes.draw do # added public route to user match 'public/:username', :to => 'users#public' match 'users/export', :to => 'users#export' + match 'users/export_photos', :to => 'users#export_photos' resources :users, :except => [:create, :new, :show] match 'aspects/move_friends', :to => 'aspects#move_friends', :as => 'move_friends' diff --git a/lib/collect_user_photos.rb b/lib/collect_user_photos.rb new file mode 100644 index 000000000..f379e9ff1 --- /dev/null +++ b/lib/collect_user_photos.rb @@ -0,0 +1,30 @@ +module PhotoMover + + def self.move_photos(user) + + Dir.chdir Rails.root + temp_dir = "tmp/exports/#{user.id}" + FileUtils::mkdir_p temp_dir + Dir.chdir 'tmp/exports' + + albums = user.visible_posts(:person_id => user.person.id, :_type => 'Album') + + albums.each do |album| + album_dir = "#{user.id}/#{album.name}" + `mkdir #{album_dir}` + + album.photos.each do |photo| + current_photo_location = "#{Rails.root}/public/uploads/images/#{photo.image_filename}" + new_photo_location = "#{album_dir}/#{photo.image_filename}" + + `cp #{current_photo_location} #{new_photo_location}` + end + end + + `tar cf #{user.id}.tar #{user.id}` + `rm -r #{user.id}` + + "#{Rails.root}/#{temp_dir}.tar" + end + +end