Make urls not change on processing
This commit is contained in:
parent
85e0736e5b
commit
fdd158d86a
6 changed files with 13 additions and 25 deletions
|
|
@ -33,8 +33,9 @@ class Photo < Post
|
|||
def self.diaspora_initialize(params = {})
|
||||
photo = super(params)
|
||||
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.update_remote_path
|
||||
photo
|
||||
end
|
||||
|
||||
|
|
@ -47,12 +48,12 @@ class Photo < Post
|
|||
end
|
||||
|
||||
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.chop! if AppConfig[:pod_url][-1,1] == '/'
|
||||
remote_path = "#{pod_url}#{self.processed_image.url}"
|
||||
remote_path = "#{pod_url}#{self.unprocessed_image.url}"
|
||||
else
|
||||
remote_path = self.processed_image.url
|
||||
remote_path = self.unprocessed_image.url
|
||||
end
|
||||
|
||||
name_start = remote_path.rindex '/'
|
||||
|
|
@ -77,7 +78,7 @@ class Photo < Post
|
|||
name = name.to_s + '_' if name
|
||||
remote_photo_path + name.to_s + remote_photo_name
|
||||
elsif not_processed?
|
||||
unprocessed_image.url
|
||||
unprocessed_image.url(name)
|
||||
else
|
||||
processed_image.url(name)
|
||||
end
|
||||
|
|
@ -102,7 +103,6 @@ class Photo < Post
|
|||
def process
|
||||
return false if unprocessed_image.path.include?('.gif') || self.processed?
|
||||
processed_image.store!(unprocessed_image) #Ultra naive
|
||||
update_remote_path
|
||||
save!
|
||||
end
|
||||
|
||||
|
|
@ -110,14 +110,6 @@ class Photo < Post
|
|||
true
|
||||
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={})
|
||||
{
|
||||
:photo => {
|
||||
|
|
|
|||
|
|
@ -226,7 +226,6 @@ class User < ActiveRecord::Base
|
|||
def update_profile(params)
|
||||
if photo = params.delete(:photo)
|
||||
photo.update_attributes(:pending => false) if photo.pending
|
||||
photo.process
|
||||
params[:image_url] = photo.url(:thumb_large)
|
||||
params[:image_url_medium] = photo.url(:thumb_medium)
|
||||
params[:image_url_small] = photo.url(:thumb_small)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class ProcessedImage < CarrierWave::Uploader::Base
|
|||
end
|
||||
|
||||
def filename
|
||||
model.random_string + model.id.to_s + File.extname(@filename) if @filename
|
||||
model.random_string + File.extname(@filename) if @filename
|
||||
end
|
||||
|
||||
version :thumb_small do
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ class UnprocessedImage < CarrierWave::Uploader::Base
|
|||
include CarrierWave::MiniMagick
|
||||
|
||||
def store_dir
|
||||
"uploads/u_images"
|
||||
"uploads/images"
|
||||
end
|
||||
|
||||
def extension_white_list
|
||||
|
|
@ -14,7 +14,11 @@ class UnprocessedImage < CarrierWave::Uploader::Base
|
|||
end
|
||||
|
||||
def filename
|
||||
model.random_string + model.id.to_s + File.extname(@filename) if @filename
|
||||
model.random_string + File.extname(@filename) if @filename
|
||||
end
|
||||
|
||||
version :thumb_small
|
||||
version :thumb_medium
|
||||
version :thumb_large
|
||||
version :scaled_full
|
||||
end
|
||||
|
|
|
|||
|
|
@ -75,9 +75,6 @@ describe Photo do
|
|||
@photo.save!
|
||||
end
|
||||
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.remote_photo_path.should include("http")
|
||||
|
|
|
|||
|
|
@ -300,10 +300,6 @@ describe User do
|
|||
alice.update_profile(@params).should be true
|
||||
@photo.reload.pending.should be_false
|
||||
end
|
||||
it 'post-processes the photo' do
|
||||
@photo.should_receive(:process)
|
||||
alice.update_profile(@params).should be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue