storage manager: remove original_subdir option.

Always store original files in `public/data/original` instead of directly in
`public/data`. Previously this was optional and defaulted to off.

Downstream boorus will need to either move all images in the
`public/data` directory to `public/data/original`, or symlink the
`public/data/original` directory to the toplevel `public/data` directory:

    ln -s . /path/to/danbooru/public/data/original

This to simplify file layout. This option existed because in the past we
stored original files in different locations on different servers (for
no particular reason).
This commit is contained in:
evazion
2021-03-15 02:07:10 -05:00
parent 0f90ae0fed
commit a620a71b59
2 changed files with 4 additions and 17 deletions

View File

@@ -1,14 +1,13 @@
class StorageManager class StorageManager
class Error < StandardError; end class Error < StandardError; end
attr_reader :base_url, :base_dir, :hierarchical, :tagged_filenames, :original_subdir attr_reader :base_url, :base_dir, :hierarchical, :tagged_filenames
def initialize(base_url:, base_dir:, hierarchical: false, tagged_filenames: Danbooru.config.enable_seo_post_urls, original_subdir: "") def initialize(base_url:, base_dir:, hierarchical: false, tagged_filenames: Danbooru.config.enable_seo_post_urls)
@base_url = base_url.chomp("/") @base_url = base_url.chomp("/")
@base_dir = base_dir @base_dir = base_dir
@hierarchical = hierarchical @hierarchical = hierarchical
@tagged_filenames = tagged_filenames @tagged_filenames = tagged_filenames
@original_subdir = original_subdir
end end
# Store the given file at the given path. If a file already exists at that # Store the given file at the given path. If a file already exists at that
@@ -56,7 +55,7 @@ class StorageManager
elsif type == :large && post.has_large? elsif type == :large && post.has_large?
"#{base_url}/sample/#{subdir}#{seo_tags}#{file}" "#{base_url}/sample/#{subdir}#{seo_tags}#{file}"
else else
"#{base_url}/#{original_subdir}#{subdir}#{seo_tags}#{post.md5}.#{post.file_ext}" "#{base_url}/original/#{subdir}#{seo_tags}#{post.md5}.#{post.file_ext}"
end end
end end
@@ -79,7 +78,7 @@ class StorageManager
when :large when :large
"#{base_dir}/sample/#{subdir}#{file}" "#{base_dir}/sample/#{subdir}#{file}"
when :original when :original
"#{base_dir}/#{original_subdir}#{subdir}#{file}" "#{base_dir}/original/#{subdir}#{file}"
end end
end end

View File

@@ -124,18 +124,6 @@ class StorageManagerTest < ActiveSupport::TestCase
assert_equal("http://localhost/images/download-preview.png", @storage_manager.file_url(@post, :preview)) assert_equal("http://localhost/images/download-preview.png", @storage_manager.file_url(@post, :preview))
end end
end end
context "when the original_subdir option is used" do
should "store original files at the correct path" do
@post = FactoryBot.create(:post, file_ext: "png")
@storage_manager = StorageManager::Local.new(base_dir: @temp_dir, base_url: "/data", original_subdir: "original/")
assert_equal("#{@temp_dir}/original/#{@post.md5}.png", @storage_manager.file_path(@post, @post.file_ext, :original))
@storage_manager.store_file(StringIO.new("data"), @post, :original)
assert_equal(true, File.exist?("#{@temp_dir}/original/#{@post.md5}.png"))
end
end
end end
context "StorageManager::Hybrid" do context "StorageManager::Hybrid" do