notify cropper service on upload
This commit is contained in:
@@ -8,24 +8,30 @@ class S3BackupService < BackupService
|
|||||||
end
|
end
|
||||||
|
|
||||||
def backup(file_path, type: nil, **options)
|
def backup(file_path, type: nil, **options)
|
||||||
key = s3_key(file_path, type)
|
keys = s3_keys(file_path, type)
|
||||||
upload_to_s3(key, file_path)
|
keys.each do |key|
|
||||||
|
upload_to_s3(key, file_path)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete(file_path, type: nil)
|
def delete(file_path, type: nil)
|
||||||
key = s3_key(file_path, type)
|
keys = s3_keys(file_path, type)
|
||||||
delete_from_s3(key)
|
keys.each do |key|
|
||||||
|
delete_from_s3(key)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def s3_key(file_path, type)
|
def s3_keys(file_path, type)
|
||||||
|
name = File.basename(file_path)
|
||||||
|
|
||||||
case type
|
case type
|
||||||
when :original
|
when :original
|
||||||
"#{File.basename(file_path)}"
|
[name]
|
||||||
when :preview
|
when :preview
|
||||||
"preview/#{File.basename(file_path)}"
|
["preview/#{name}", "cropped/small/#{name}", "cropped/large/#{name}"]
|
||||||
when :large
|
when :large
|
||||||
"sample/#{File.basename(file_path)}"
|
["sample/#{name}"]
|
||||||
else
|
else
|
||||||
raise ArgumentError.new("Unknown type: #{type}")
|
raise ArgumentError.new("Unknown type: #{type}")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ class Upload < ApplicationRecord
|
|||||||
User.where(id: CurrentUser.id).update_all("post_upload_count = post_upload_count + 1")
|
User.where(id: CurrentUser.id).update_all("post_upload_count = post_upload_count + 1")
|
||||||
create_artist_commentary(post) if include_artist_commentary?
|
create_artist_commentary(post) if include_artist_commentary?
|
||||||
ugoira_service.save_frame_data(post) if is_ugoira?
|
ugoira_service.save_frame_data(post) if is_ugoira?
|
||||||
|
notify_cropper(post)
|
||||||
update_attributes(:status => "completed", :post_id => post.id)
|
update_attributes(:status => "completed", :post_id => post.id)
|
||||||
else
|
else
|
||||||
update_attribute(:status, "error: " + post.errors.full_messages.join(", "))
|
update_attribute(:status, "error: " + post.errors.full_messages.join(", "))
|
||||||
@@ -197,6 +198,13 @@ class Upload < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
module FileMethods
|
module FileMethods
|
||||||
|
|||||||
Reference in New Issue
Block a user