fixes #3180
This commit is contained in:
@@ -12,6 +12,11 @@ class S3BackupService < BackupService
|
|||||||
upload_to_s3(key, file_path)
|
upload_to_s3(key, file_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete(file_path, type: nil)
|
||||||
|
key = s3_key(file_path, type)
|
||||||
|
delete_from_s3(key)
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def s3_key(file_path, type)
|
def s3_key(file_path, type)
|
||||||
case type
|
case type
|
||||||
@@ -26,6 +31,12 @@ protected
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete_from_s3(key)
|
||||||
|
client.delete_object(bucket: bucket, key: key)
|
||||||
|
rescue Aws::S3::Errors::NoSuchKey
|
||||||
|
# ignore
|
||||||
|
end
|
||||||
|
|
||||||
def upload_to_s3(key, file_path)
|
def upload_to_s3(key, file_path)
|
||||||
File.open(file_path, "rb") do |body|
|
File.open(file_path, "rb") do |body|
|
||||||
base64_md5 = Digest::MD5.base64digest(File.read(file_path))
|
base64_md5 = Digest::MD5.base64digest(File.read(file_path))
|
||||||
|
|||||||
@@ -74,6 +74,10 @@ class Post < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
backup_service.delete(file_path, type: :original)
|
||||||
|
backup_service.delete(large_file_path, type: :large)
|
||||||
|
backup_service.delete(preview_file_path, type: :preview)
|
||||||
|
|
||||||
# the large file and the preview don't necessarily exist. if so errors will be ignored.
|
# the large file and the preview don't necessarily exist. if so errors will be ignored.
|
||||||
FileUtils.rm_f(file_path)
|
FileUtils.rm_f(file_path)
|
||||||
FileUtils.rm_f(large_file_path)
|
FileUtils.rm_f(large_file_path)
|
||||||
|
|||||||
@@ -18,11 +18,6 @@ class PostReplacement < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def process!
|
def process!
|
||||||
# TODO images hosted on s3 need to be deleted from s3 instead of the local filesystem.
|
|
||||||
if Danbooru.config.use_s3_proxy?(post)
|
|
||||||
raise NotImplementedError.new("Replacing S3 hosted images not yet supported.")
|
|
||||||
end
|
|
||||||
|
|
||||||
transaction do
|
transaction do
|
||||||
upload = Upload.create!(file: replacement_file, source: replacement_url, rating: post.rating, tag_string: self.tags)
|
upload = Upload.create!(file: replacement_file, source: replacement_url, rating: post.rating, tag_string: self.tags)
|
||||||
upload.process_upload
|
upload.process_upload
|
||||||
|
|||||||
Reference in New Issue
Block a user