Clarify image path methods for SwfAsset
Using `s3_path` and stuff made it sound like we were still referencing the original Amazon S3 images - but actually our new asset proxy just uses the same path structure, and we didn't change anything about it. Oh also I deleted an after_conversion method that isn't used anymore, forgot about that!
This commit is contained in:
parent
8a20c9be02
commit
b8559f33cb
1 changed files with 3 additions and 36 deletions
|
@ -42,44 +42,10 @@ class SwfAsset < ActiveRecord::Base
|
||||||
swf_image_dir.join("#{size.join 'x'}.png")
|
swf_image_dir.join("#{size.join 'x'}.png")
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_swf_conversion(images)
|
|
||||||
images.each do |size, path|
|
|
||||||
key = s3_key(size)
|
|
||||||
print "Uploading #{key}..."
|
|
||||||
IMAGE_BUCKET.put(
|
|
||||||
key,
|
|
||||||
File.open(path),
|
|
||||||
{}, # meta headers
|
|
||||||
IMAGE_PERMISSION, # permission
|
|
||||||
IMAGE_HEADERS
|
|
||||||
)
|
|
||||||
puts "done."
|
|
||||||
|
|
||||||
FileUtils.rm path
|
|
||||||
end
|
|
||||||
FileUtils.rmdir swf_image_dir
|
|
||||||
|
|
||||||
self.converted_at = Time.now
|
|
||||||
self.has_image = true
|
|
||||||
self.save!
|
|
||||||
end
|
|
||||||
|
|
||||||
def s3_key(size)
|
|
||||||
URI.encode("#{s3_path}/#{size.join 'x'}.png")
|
|
||||||
end
|
|
||||||
|
|
||||||
def s3_path
|
|
||||||
"#{self['type']}/#{s3_partition_path}#{self.remote_id}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def s3_url(size)
|
|
||||||
"#{IMAGE_BUCKET.public_link}/#{s3_path}/#{size.join 'x'}.png"
|
|
||||||
end
|
|
||||||
|
|
||||||
PARTITION_COUNT = 3
|
PARTITION_COUNT = 3
|
||||||
PARTITION_DIGITS = 3
|
PARTITION_DIGITS = 3
|
||||||
PARTITION_ID_LENGTH = PARTITION_COUNT * PARTITION_DIGITS
|
PARTITION_ID_LENGTH = PARTITION_COUNT * PARTITION_DIGITS
|
||||||
def s3_partition_path
|
def partition_path
|
||||||
(remote_id / 10**PARTITION_DIGITS).to_s.rjust(PARTITION_ID_LENGTH, '0').tap do |id_str|
|
(remote_id / 10**PARTITION_DIGITS).to_s.rjust(PARTITION_ID_LENGTH, '0').tap do |id_str|
|
||||||
PARTITION_COUNT.times do |n|
|
PARTITION_COUNT.times do |n|
|
||||||
id_str.insert(PARTITION_ID_LENGTH - (n * PARTITION_DIGITS), '/')
|
id_str.insert(PARTITION_ID_LENGTH - (n * PARTITION_DIGITS), '/')
|
||||||
|
@ -95,7 +61,8 @@ class SwfAsset < ActiveRecord::Base
|
||||||
host = ASSET_HOSTS[:swf_asset_images]
|
host = ASSET_HOSTS[:swf_asset_images]
|
||||||
size_key = size.join('x')
|
size_key = size.join('x')
|
||||||
|
|
||||||
"//#{host}/#{s3_path}/#{size_key}.png?#{image_version}"
|
image_dir = "#{self['type']}/#{partition_path}#{self.remote_id}"
|
||||||
|
"//#{host}/#{image_dir}/#{size_key}.png?#{image_version}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def images
|
def images
|
||||||
|
|
Loading…
Reference in a new issue