Merge branch 'master' of github.com:diaspora/diaspora
This commit is contained in:
commit
c75a2ebd66
4 changed files with 39 additions and 1 deletions
|
|
@ -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] == '/'
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
30
lib/collect_user_photos.rb
Normal file
30
lib/collect_user_photos.rb
Normal file
|
|
@ -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
|
||||
Loading…
Reference in a new issue