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:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user