media assets: move more file-handling logic into MediaAsset.
Move more of the file-handling logic from UploadService and StorageManager into MediaAsset. This is part of refactoring posts and uploads to allow multiple images per post.
This commit is contained in:
@@ -3,7 +3,7 @@ class StorageManager::Local < StorageManager
|
||||
DEFAULT_PERMISSIONS = 0o644
|
||||
|
||||
def store(io, dest_path)
|
||||
temp_path = dest_path + "-" + SecureRandom.uuid + ".tmp"
|
||||
temp_path = full_path(dest_path) + "-" + SecureRandom.uuid + ".tmp"
|
||||
|
||||
FileUtils.mkdir_p(File.dirname(temp_path))
|
||||
io.rewind
|
||||
@@ -11,17 +11,17 @@ class StorageManager::Local < StorageManager
|
||||
raise Error, "store failed: #{bytes_copied}/#{io.size} bytes copied" if bytes_copied != io.size
|
||||
|
||||
FileUtils.chmod(DEFAULT_PERMISSIONS, temp_path)
|
||||
File.rename(temp_path, dest_path)
|
||||
File.rename(temp_path, full_path(dest_path))
|
||||
rescue StandardError => e
|
||||
FileUtils.rm_f(temp_path)
|
||||
raise Error, e
|
||||
end
|
||||
|
||||
def delete(path)
|
||||
FileUtils.rm_f(path)
|
||||
FileUtils.rm_f(full_path(path))
|
||||
end
|
||||
|
||||
def open(path)
|
||||
File.open(path, "r", binmode: true)
|
||||
File.open(full_path(path), "r", binmode: true)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -35,6 +35,6 @@ class StorageManager::Rclone < StorageManager
|
||||
end
|
||||
|
||||
def key(path)
|
||||
":#{remote}:#{bucket}#{path}"
|
||||
":#{remote}:#{bucket}#{full_path(path)}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,6 +19,7 @@ class StorageManager::SFTP < StorageManager
|
||||
end
|
||||
|
||||
def store(file, dest_path)
|
||||
dest_path = full_path(dest_path)
|
||||
temp_upload_path = dest_path + "-" + SecureRandom.uuid + ".tmp"
|
||||
dest_backup_path = dest_path + "-" + SecureRandom.uuid + ".bak"
|
||||
|
||||
@@ -42,7 +43,7 @@ class StorageManager::SFTP < StorageManager
|
||||
|
||||
def delete(dest_path)
|
||||
each_host do |_host, sftp|
|
||||
force { sftp.remove!(dest_path) }
|
||||
force { sftp.remove!(full_path(dest_path)) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -50,7 +51,7 @@ class StorageManager::SFTP < StorageManager
|
||||
file = Tempfile.new(binmode: true)
|
||||
|
||||
Net::SFTP.start(hosts.first, nil, ssh_options) do |sftp|
|
||||
sftp.download!(dest_path, file.path)
|
||||
sftp.download!(full_path(dest_path), file.path)
|
||||
end
|
||||
|
||||
file
|
||||
|
||||
Reference in New Issue
Block a user