Fix #4260: Unable to replace cdn.donmai.us images?

Bug: Replacing posts hosted on cdn.donmai.us didn't work.

Cause: Original files on cdn.donmai.us are hosted under /var/www/danbooru/original/, but replacements
were trying to store them directly under /var/www/danbooru, which failed with a permission error.
We were trying to store them in the wrong directory because we didn't respect the `original_subdir`
option when generating file paths.
This commit is contained in:
evazion
2020-06-09 15:45:56 -05:00
parent 20abd8a5fd
commit 15799f8af7
2 changed files with 13 additions and 1 deletions

View File

@@ -85,7 +85,7 @@ class StorageManager
when :large
"#{base_dir}/sample/#{subdir}#{file}"
when :original
"#{base_dir}/#{subdir}#{file}"
"#{base_dir}/#{original_subdir}#{subdir}#{file}"
end
end

View File

@@ -130,6 +130,18 @@ class StorageManagerTest < ActiveSupport::TestCase
assert_equal("http://localhost/images/download-preview.png", @storage_manager.file_url(@post, :preview))
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: BASE_DIR, base_url: "/data", original_subdir: "original/")
assert_equal("#{BASE_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?("#{BASE_DIR}/original/#{@post.md5}.png"))
end
end
end
context "StorageManager::Hybrid" do