Commit e808a4f7 authored by Albert Yi's avatar Albert Yi

delete unfinished upload files

parent fdd7582f
......@@ -57,6 +57,19 @@ class UploadService
end
end
def self.delete_file(md5, file_ext)
if Post.where(md5: md5).exists?
return
end
Danbooru.config.storage_manager.delete_file(nil, md5, file_ext, :original)
Danbooru.config.storage_manager.delete_file(nil, md5, file_ext, :large)
Danbooru.config.storage_manager.delete_file(nil, md5, file_ext, :preview)
Danbooru.config.backup_storage_manager.delete_file(nil, md5, file_ext, :original)
Danbooru.config.backup_storage_manager.delete_file(nil, md5, file_ext, :large)
Danbooru.config.backup_storage_manager.delete_file(nil, md5, file_ext, :preview)
end
def self.calculate_ugoira_dimensions(source_path)
folder = Zip::File.new(source_path)
Tempfile.open("ugoira-dim-") do |tempfile|
......@@ -147,6 +160,12 @@ class UploadService
preview_file.try(:close!)
sample_file.try(:close!)
end
# in case this upload never finishes processing, we need to delete the
# distributed files in the future
Danbooru.config.other_server_hosts.each do |host|
UploadService::Utils.delay(queue: host, run_at: 10.minutes.from_now).delete_file(upload.md5, upload.file_ext)
end
end
# these methods are only really used during upload processing even
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment