notify cropper service on upload
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -142,6 +142,7 @@ class Upload < ApplicationRecord
|
||||
User.where(id: CurrentUser.id).update_all("post_upload_count = post_upload_count + 1")
|
||||
create_artist_commentary(post) if include_artist_commentary?
|
||||
ugoira_service.save_frame_data(post) if is_ugoira?
|
||||
notify_cropper(post)
|
||||
update_attributes(:status => "completed", :post_id => post.id)
|
||||
else
|
||||
update_attribute(:status, "error: " + post.errors.full_messages.join(", "))
|
||||
@@ -197,6 +198,13 @@ class Upload < ApplicationRecord
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def notify_cropper(post)
|
||||
if Danbooru.config.aws_sqs_cropper_url && is_image?
|
||||
sqs = SqsService.new(Danbooru.config.aws_sqs_cropper_url)
|
||||
sqs.send_message("#{post.id},https://#{Danbooru.config.hostnames.first}/data/#{post.md5}.#{post.file_ext}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module FileMethods
|
||||
|
||||
Reference in New Issue
Block a user