notify cropper service on upload

This commit is contained in:
r888888888
2017-09-08 17:11:51 -07:00
parent 99e38c9e95
commit ff6a64f0fc
2 changed files with 22 additions and 8 deletions

View File

@@ -8,24 +8,30 @@ class S3BackupService < BackupService
end
def backup(file_path, type: nil, **options)
key = s3_key(file_path, type)
upload_to_s3(key, file_path)
keys = s3_keys(file_path, type)
keys.each do |key|
upload_to_s3(key, file_path)
end
end
def delete(file_path, type: nil)
key = s3_key(file_path, type)
delete_from_s3(key)
keys = s3_keys(file_path, type)
keys.each do |key|
delete_from_s3(key)
end
end
protected
def s3_key(file_path, type)
def s3_keys(file_path, type)
name = File.basename(file_path)
case type
when :original
"#{File.basename(file_path)}"
[name]
when :preview
"preview/#{File.basename(file_path)}"
["preview/#{name}", "cropped/small/#{name}", "cropped/large/#{name}"]
when :large
"sample/#{File.basename(file_path)}"
["sample/#{name}"]
else
raise ArgumentError.new("Unknown type: #{type}")
end