Skip to content
Extraits de code Groupes Projets
Valider fdd158d8 rédigé par Raphael Sofaer's avatar Raphael Sofaer
Parcourir les fichiers

Make urls not change on processing

parent 85e0736e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -33,8 +33,9 @@ class Photo < Post ...@@ -33,8 +33,9 @@ class Photo < Post
def self.diaspora_initialize(params = {}) def self.diaspora_initialize(params = {})
photo = super(params) photo = super(params)
image_file = params.delete(:user_file) image_file = params.delete(:user_file)
photo.random_string = gen_random_string(10) photo.random_string = ActiveSupport::SecureRandom.hex(10)
photo.unprocessed_image.store! image_file photo.unprocessed_image.store! image_file
photo.update_remote_path
photo photo
end end
...@@ -47,12 +48,12 @@ class Photo < Post ...@@ -47,12 +48,12 @@ class Photo < Post
end end
def update_remote_path def update_remote_path
unless self.processed_image.url.match(/^https?:\/\//) unless self.unprocessed_image.url.match(/^https?:\/\//)
pod_url = AppConfig[:pod_url].dup pod_url = AppConfig[:pod_url].dup
pod_url.chop! if AppConfig[:pod_url][-1,1] == '/' pod_url.chop! if AppConfig[:pod_url][-1,1] == '/'
remote_path = "#{pod_url}#{self.processed_image.url}" remote_path = "#{pod_url}#{self.unprocessed_image.url}"
else else
remote_path = self.processed_image.url remote_path = self.unprocessed_image.url
end end
name_start = remote_path.rindex '/' name_start = remote_path.rindex '/'
...@@ -77,7 +78,7 @@ class Photo < Post ...@@ -77,7 +78,7 @@ class Photo < Post
name = name.to_s + '_' if name name = name.to_s + '_' if name
remote_photo_path + name.to_s + remote_photo_name remote_photo_path + name.to_s + remote_photo_name
elsif not_processed? elsif not_processed?
unprocessed_image.url unprocessed_image.url(name)
else else
processed_image.url(name) processed_image.url(name)
end end
...@@ -102,7 +103,6 @@ class Photo < Post ...@@ -102,7 +103,6 @@ class Photo < Post
def process def process
return false if unprocessed_image.path.include?('.gif') || self.processed? return false if unprocessed_image.path.include?('.gif') || self.processed?
processed_image.store!(unprocessed_image) #Ultra naive processed_image.store!(unprocessed_image) #Ultra naive
update_remote_path
save! save!
end end
...@@ -110,14 +110,6 @@ class Photo < Post ...@@ -110,14 +110,6 @@ class Photo < Post
true true
end end
def self.gen_random_string(len)
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
string = ""
1.upto(len) { |i| string << chars[rand(chars.size-1)] }
return string
end
def as_json(opts={}) def as_json(opts={})
{ {
:photo => { :photo => {
......
...@@ -226,7 +226,6 @@ class User < ActiveRecord::Base ...@@ -226,7 +226,6 @@ class User < ActiveRecord::Base
def update_profile(params) def update_profile(params)
if photo = params.delete(:photo) if photo = params.delete(:photo)
photo.update_attributes(:pending => false) if photo.pending photo.update_attributes(:pending => false) if photo.pending
photo.process
params[:image_url] = photo.url(:thumb_large) params[:image_url] = photo.url(:thumb_large)
params[:image_url_medium] = photo.url(:thumb_medium) params[:image_url_medium] = photo.url(:thumb_medium)
params[:image_url_small] = photo.url(:thumb_small) params[:image_url_small] = photo.url(:thumb_small)
......
...@@ -14,7 +14,7 @@ class ProcessedImage < CarrierWave::Uploader::Base ...@@ -14,7 +14,7 @@ class ProcessedImage < CarrierWave::Uploader::Base
end end
def filename def filename
model.random_string + model.id.to_s + File.extname(@filename) if @filename model.random_string + File.extname(@filename) if @filename
end end
version :thumb_small do version :thumb_small do
......
...@@ -6,7 +6,7 @@ class UnprocessedImage < CarrierWave::Uploader::Base ...@@ -6,7 +6,7 @@ class UnprocessedImage < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick include CarrierWave::MiniMagick
def store_dir def store_dir
"uploads/u_images" "uploads/images"
end end
def extension_white_list def extension_white_list
...@@ -14,7 +14,11 @@ class UnprocessedImage < CarrierWave::Uploader::Base ...@@ -14,7 +14,11 @@ class UnprocessedImage < CarrierWave::Uploader::Base
end end
def filename def filename
model.random_string + model.id.to_s + File.extname(@filename) if @filename model.random_string + File.extname(@filename) if @filename
end end
version :thumb_small
version :thumb_medium
version :thumb_large
version :scaled_full
end end
...@@ -75,9 +75,6 @@ describe Photo do ...@@ -75,9 +75,6 @@ describe Photo do
@photo.save! @photo.save!
end end
it 'sets a remote url' do it 'sets a remote url' do
@photo.remote_photo_path.should be_nil
@photo.remote_photo_name.should be_nil
@photo.update_remote_path @photo.update_remote_path
@photo.remote_photo_path.should include("http") @photo.remote_photo_path.should include("http")
......
...@@ -300,10 +300,6 @@ describe User do ...@@ -300,10 +300,6 @@ describe User do
alice.update_profile(@params).should be true alice.update_profile(@params).should be true
@photo.reload.pending.should be_false @photo.reload.pending.should be_false
end end
it 'post-processes the photo' do
@photo.should_receive(:process)
alice.update_profile(@params).should be true
end
end end
end end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter