Fix #4142: Missing images after upload.

This commit is contained in:
evazion
2019-09-01 13:10:37 -05:00
parent 67100f26eb
commit a932b25608
6 changed files with 75 additions and 32 deletions

View File

@@ -67,6 +67,9 @@ class Upload < ApplicationRecord
validates :md5, confirmation: true, if: -> (rec) { rec.md5_confirmation.present? }
validates_with FileValidator, on: :file
serialize :context, JSON
after_destroy_commit :delete_files
scope :preprocessed, -> { where(status: "preprocessed") }
def initialize_attributes
@@ -75,6 +78,10 @@ class Upload < ApplicationRecord
self.server = Danbooru.config.server_host
end
def self.prune!(date = 1.day.ago)
where("created_at < ?", date).lock.destroy_all
end
module FileMethods
def is_image?
%w(jpg gif png).include?(file_ext)
@@ -91,6 +98,21 @@ class Upload < ApplicationRecord
def is_ugoira?
%w(zip).include?(file_ext)
end
def delete_files
# md5 is blank if the upload errored out before downloading the file.
if md5.blank? || Upload.where(md5: md5).exists? || Post.where(md5: md5).exists?
return
end
DanbooruLogger.info("Uploads: Deleting files for upload md5=#{md5}", upload: as_json)
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
end
module StatusMethods