maintain current directory structure for images

This commit is contained in:
albert 2012-08-21 18:29:09 -04:00
parent c65feee149
commit e7d6b8c449
6 changed files with 899 additions and 148 deletions

View File

@ -90,12 +90,12 @@ class Post < ActiveRecord::Base
end
def file_path
"#{Rails.root}/public/data/original/#{file_path_prefix}#{md5}.#{file_ext}"
"#{Rails.root}/public/data/#{file_path_prefix}#{md5}.#{file_ext}"
end
def large_file_path
if has_large?
"#{Rails.root}/public/data/large/#{file_path_prefix}#{md5}.jpg"
"#{Rails.root}/public/data/sample/#{file_path_prefix}#{Danbooru.config.large_image_prefix}#{md5}.jpg"
else
file_path
end
@ -118,12 +118,12 @@ class Post < ActiveRecord::Base
end
def file_url
"/data/original/#{file_path_prefix}#{md5}.#{file_ext}"
"/data/#{file_path_prefix}#{md5}.#{file_ext}"
end
def large_file_url
if has_large?
"/data/large/#{file_path_prefix}#{md5}.jpg"
"/data/sample/#{file_path_prefix}#{Danbooru.config.large_image_prefix}#{md5}.jpg"
else
file_url
end

View File

@ -209,7 +209,7 @@ class Upload < ActiveRecord::Base
module FilePathMethods
def md5_file_path
prefix = Rails.env == "test" ? "test." : ""
"#{Rails.root}/public/data/original/#{prefix}#{md5}.#{file_ext}"
"#{Rails.root}/public/data/#{prefix}#{md5}.#{file_ext}"
end
def resized_file_path_for(width)
@ -220,7 +220,7 @@ class Upload < ActiveRecord::Base
"#{Rails.root}/public/data/preview/#{prefix}#{md5}.jpg"
when Danbooru.config.large_image_width
"#{Rails.root}/public/data/large/#{prefix}#{md5}.jpg"
"#{Rails.root}/public/data/sample/#{prefix}#{md5}.jpg"
end
end

View File

@ -73,6 +73,10 @@ module Danbooru
900
end
def large_image_prefix
"sample-"
end
# When calculating statistics based on the posts table, gather this many posts to sample from.
def post_sample_size
300

View File

@ -44,8 +44,7 @@ namespace :data do
task :setup_directories do
run "mkdir -p #{deploy_to}/shared/data"
run "mkdir #{deploy_to}/shared/data/preview"
run "mkdir #{deploy_to}/shared/data/large"
run "mkdir #{deploy_to}/shared/data/original"
run "mkdir #{deploy_to}/shared/data/sample"
end
task :link_directories do

File diff suppressed because it is too large Load Diff

View File

@ -110,8 +110,8 @@ class UploadTest < ActiveSupport::TestCase
context "resizer" do
teardown do
FileUtils.rm_f(Dir.glob("#{Rails.root}/public/data/preview/test.*.jpg"))
FileUtils.rm_f(Dir.glob("#{Rails.root}/public/data/large/test.*.jpg"))
FileUtils.rm_f(Dir.glob("#{Rails.root}/public/data/original/test.*.jpg"))
FileUtils.rm_f(Dir.glob("#{Rails.root}/public/data/sample/test.*.jpg"))
FileUtils.rm_f(Dir.glob("#{Rails.root}/public/data/test.*.jpg"))
end
should "generate several resized versions of the image" do