From 7ed31ab96a836a9e7c8b6e51399cf2d68cb51dc9 Mon Sep 17 00:00:00 2001 From: Raphael <raphael@joindiaspora.com> Date: Wed, 18 Aug 2010 16:37:05 -0700 Subject: [PATCH] Moving to file store --- app/models/album.rb | 1 - app/models/photo.rb | 19 ++++++++++++++----- app/uploaders/image_uploader.rb | 4 ++-- app/views/albums/_album.html.haml | 2 +- app/views/albums/edit.html.haml | 2 +- app/views/albums/show.html.haml | 2 +- app/views/photos/show.html.haml | 2 +- app/views/users/edit.html.haml | 6 +++--- config/initializers/carrierwave.rb | 6 +----- config/routes.rb | 2 -- spec/models/photo_spec.rb | 5 ++--- 11 files changed, 26 insertions(+), 25 deletions(-) diff --git a/app/models/album.rb b/app/models/album.rb index b30cb5c45d..b6daabb474 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -27,7 +27,6 @@ class Album def self.mine_or_friends(friend_param, current_user) if friend_param - puts "i am working" Album.find_all_by_person_id(current_user.friend_ids) else current_user.person.albums diff --git a/app/models/photo.rb b/app/models/photo.rb index d93a1189a9..b43ddc376f 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -35,15 +35,24 @@ class Photo < Post def validate_album_person album.person_id == person_id end - + def remote_photo - @remote_photo ||= self.person.url.chop + image.url + url end def remote_photo= remote_path - @remote_photo = remote_path - image.download! remote_path - image.store! + name_start = remote_path.rindex '/' + @remote_photo_path = remote_path.slice(0, name_start ) + @remote_photo_name = remote_path.slice(name_start, remote_path.length) + puts url + end + + def url name = nil + if @remote_photo_path + @remote_photo_path + name.to_s + @remote_photo_name + else + image.url name + end end def ensure_user_picture diff --git a/app/uploaders/image_uploader.rb b/app/uploaders/image_uploader.rb index 2a55e30592..3fd36c6a60 100644 --- a/app/uploaders/image_uploader.rb +++ b/app/uploaders/image_uploader.rb @@ -1,10 +1,10 @@ class ImageUploader < CarrierWave::Uploader::Base include CarrierWave::MiniMagick - storage :grid_fs + storage :file def store_dir - "files" + "uploads/images" end def extension_white_list diff --git a/app/views/albums/_album.html.haml b/app/views/albums/_album.html.haml index 52cb7fe4ae..3e4bf3483c 100644 --- a/app/views/albums/_album.html.haml +++ b/app/views/albums/_album.html.haml @@ -11,5 +11,5 @@ %div.image_cycle - for photo in post.photos[0..3] - = link_to (image_tag photo.image.url(:thumb_large)), album_path(post) + = link_to (image_tag photo.url(:thumb_large)), album_path(post) diff --git a/app/views/albums/edit.html.haml b/app/views/albums/edit.html.haml index b505cf76b6..18cb8b6447 100644 --- a/app/views/albums/edit.html.haml +++ b/app/views/albums/edit.html.haml @@ -13,7 +13,7 @@ %ul - for photo in @album.photos - %li.photo_edit_block= image_tag photo.image.url(:thumb_large) + %li.photo_edit_block= image_tag photo.url(:thumb_large) #submit_block = link_to "Cancel", root_path diff --git a/app/views/albums/show.html.haml b/app/views/albums/show.html.haml index b63dea9de9..04b1176456 100644 --- a/app/views/albums/show.html.haml +++ b/app/views/albums/show.html.haml @@ -22,7 +22,7 @@ #thumbnails - for photo in @album_photos .image_thumb - = link_to (image_tag photo.image.url(:thumb_medium)), object_path(photo) + = link_to (image_tag photo.url(:thumb_medium)), object_path(photo) #content_bottom .back diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml index 05443591f8..8636998b3e 100644 --- a/app/views/photos/show.html.haml +++ b/app/views/photos/show.html.haml @@ -8,7 +8,7 @@ .sub_header = link_to_prev @photo, @album | - = link_to "full size", @photo.image.url + = link_to "full size", @photo.url | = link_to_next @photo, @album diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index fa1136fec5..24aa8e7f01 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -15,14 +15,14 @@ %div#image_picker = p.hidden_field :image_url, :value => @profile.image_url, :id => 'image_url_field' - for photo in @photos - - if photo.image.url(:thumb_medium) == @profile.image_url + - if photo.url(:thumb_medium) == @profile.image_url %div.small_photo{:id => photo.image.thumb_medium.url, :class=>'selected'} = check_box_tag 'checked_photo', true, true - = link_to image_tag(photo.image.url(:thumb_medium)), "#" + = link_to image_tag(photo.url(:thumb_medium)), "#" - else %div.small_photo{:id => photo.image.thumb_medium.url} = check_box_tag 'checked_photo' - = link_to image_tag(photo.image.url(:thumb_medium)), "#" + = link_to image_tag(photo.url(:thumb_medium)), "#" =will_paginate @photos diff --git a/config/initializers/carrierwave.rb b/config/initializers/carrierwave.rb index ed6e8bb4ec..0fe280e023 100644 --- a/config/initializers/carrierwave.rb +++ b/config/initializers/carrierwave.rb @@ -1,7 +1,3 @@ CarrierWave.configure do |config| - config.grid_fs_database = MongoMapper::database.name - config.grid_fs_host = MongoMapper::connection.host - config.grid_fs_access_url = "/images" - config.storage = :grid_fs - #config.storage = :file + config.storage = :file end diff --git a/config/routes.rb b/config/routes.rb index e1991d0330..e8d5616f0a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,8 +8,6 @@ Diaspora::Application.routes.draw do |map| resources :albums resources :groups - match "/images/files/*path" => "gridfs#serve" - match 'warzombie', :to => "dev_utilities#warzombie" match 'zombiefriends', :to => "dev_utilities#zombiefriends" match 'zombiefriendaccept', :to => "dev_utilities#zombiefriendaccept" diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index 3d4d830082..c91fd3c1a7 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -19,7 +19,7 @@ describe Photo do photo.image.read.nil?.should be false end - it 'should save a photo to GridFS' do + it 'should save a photo' do @photo.image.store! File.open(@fixture_name) @photo.save.should == true binary = @photo.image.read @@ -58,7 +58,6 @@ describe Photo do end it 'should not use the imported filename as the url' do - pending "Until this passes, duplicate photos will cause errors" @photo.image.store! File.open(@fixture_name) @photo.image.url.include?(@fixture_filename).should be false @photo.image.url(:thumb_medium).include?("/" + @fixture_filename).should be false @@ -85,7 +84,7 @@ describe Photo do stub_signature_verification end - it 'should save a signed photo to GridFS' do + it 'should save a signed photo' do photo = @user.post(:photo, :album => @album, :user_file => [File.open(@fixture_name)]) photo.save.should == true photo.signature_valid?.should be true -- GitLab