2010-04-20 23:05:11 +00:00
|
|
|
module PostImageStoreMethods
|
|
|
|
module LocalHierarchy
|
|
|
|
def file_hierarchy
|
|
|
|
"%s/%s" % [md5[0,2], md5[2,2]]
|
|
|
|
end
|
|
|
|
|
|
|
|
def file_path
|
2012-04-29 10:56:41 -07:00
|
|
|
"#{Rails.root}/public/data/image/#{file_hierarchy}/#{file_name}"
|
2010-04-20 23:05:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def file_url
|
|
|
|
if CONFIG["use_pretty_image_urls"] then
|
|
|
|
CONFIG["url_base"] + "/image/#{md5}/#{url_encode(pretty_file_name)}.#{file_ext}"
|
|
|
|
else
|
|
|
|
CONFIG["url_base"] + "/data/image/#{file_hierarchy}/#{file_name}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def preview_path
|
|
|
|
if status == "deleted"
|
2012-04-29 10:56:41 -07:00
|
|
|
"#{Rails.root}/public/deleted-preview.png"
|
2010-04-20 23:05:11 +00:00
|
|
|
elsif image?
|
2012-04-29 10:56:41 -07:00
|
|
|
"#{Rails.root}/public/data/preview/#{file_hierarchy}/#{md5}.jpg"
|
2010-04-20 23:05:11 +00:00
|
|
|
else
|
2012-04-29 10:56:41 -07:00
|
|
|
"#{Rails.root}/public/download-preview.png"
|
2010-04-20 23:05:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def sample_path
|
2012-04-29 10:56:41 -07:00
|
|
|
"#{Rails.root}/public/data/sample/#{file_hierarchy}/" + CONFIG["sample_filename_prefix"] + "#{md5}.jpg"
|
2010-04-20 23:05:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def preview_url
|
|
|
|
if image?
|
|
|
|
CONFIG["url_base"] + "/data/preview/#{file_hierarchy}/#{md5}.jpg"
|
|
|
|
else
|
|
|
|
CONFIG["url_base"] + "/download-preview.png"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def jpeg_path
|
2012-04-29 10:56:41 -07:00
|
|
|
"#{Rails.root}/public/data/jpeg/#{file_hierarchy}/#{md5}.jpg"
|
2010-04-20 23:05:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def store_jpeg_url
|
|
|
|
if CONFIG["use_pretty_image_urls"] then
|
|
|
|
CONFIG["url_base"] + "/jpeg/#{md5}/#{url_encode(pretty_file_name({:type => :jpeg}))}.jpg"
|
|
|
|
else
|
|
|
|
CONFIG["url_base"] + "/data/jpeg/#{file_hierarchy}/#{md5}.jpg"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def store_sample_url
|
|
|
|
if CONFIG["use_pretty_image_urls"] then
|
|
|
|
CONFIG["url_base"] + "/sample/#{md5}/#{url_encode(pretty_file_name({:type => :sample}))}.jpg"
|
|
|
|
else
|
|
|
|
CONFIG["url_base"] + "/data/sample/#{file_hierarchy}/" + CONFIG["sample_filename_prefix"] + "#{md5}.jpg"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete_file
|
|
|
|
FileUtils.rm_f(file_path)
|
|
|
|
FileUtils.rm_f(preview_path) if image?
|
|
|
|
FileUtils.rm_f(sample_path) if image?
|
|
|
|
FileUtils.rm_f(jpeg_path) if image?
|
|
|
|
end
|
|
|
|
|
|
|
|
def move_file
|
2010-11-15 13:57:30 +00:00
|
|
|
FileUtils.mkdir_p(File.dirname(file_path), :mode => 0775)
|
|
|
|
FileUtils.mv(tempfile_path, file_path)
|
|
|
|
FileUtils.chmod(0664, file_path)
|
2010-04-20 23:05:11 +00:00
|
|
|
|
2010-11-15 13:57:30 +00:00
|
|
|
if image?
|
2010-04-20 23:05:11 +00:00
|
|
|
FileUtils.mkdir_p(File.dirname(preview_path), :mode => 0775)
|
|
|
|
FileUtils.mv(tempfile_preview_path, preview_path)
|
|
|
|
FileUtils.chmod(0664, preview_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
if File.exists?(tempfile_sample_path)
|
|
|
|
FileUtils.mkdir_p(File.dirname(sample_path), :mode => 0775)
|
|
|
|
FileUtils.mv(tempfile_sample_path, sample_path)
|
|
|
|
FileUtils.chmod(0664, sample_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
if File.exists?(tempfile_jpeg_path)
|
|
|
|
FileUtils.mkdir_p(File.dirname(jpeg_path), :mode => 0775)
|
|
|
|
FileUtils.mv(tempfile_jpeg_path, jpeg_path)
|
|
|
|
FileUtils.chmod(0664, jpeg_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
delete_tempfile
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|