uploads: autotag animated_gif/png during upload.

Move animated_gif / animated_png autotagging to take place during
uploading, instead of during tag editing. We can't generally assume the
file will be present on the local filesystem after uploading.
This commit is contained in:
evazion
2018-03-18 11:55:24 -05:00
parent 2286ccfca8
commit 60dcfbfbdd
3 changed files with 23 additions and 34 deletions

View File

@@ -86,7 +86,7 @@ class APNGInspector
end
@corrupted = !read_success || actl_corrupted
return !@corrupted
self
end
def corrupted?
@@ -109,4 +109,4 @@ class APNGInspector
return framedata.unpack("N".freeze)[0]
end
end
end

View File

@@ -255,24 +255,6 @@ class Post < ApplicationRecord
file_ext =~ /jpg|jpeg|gif|png/i
end
def is_animated_gif?
if file_ext =~ /gif/i && File.exists?(file_path)
return Magick::Image.ping(file_path).length > 1
else
return false
end
end
def is_animated_png?
if file_ext =~ /png/i && File.exists?(file_path)
apng = APNGInspector.new(file_path)
apng.inspect!
return apng.animated?
else
return false
end
end
def is_flash?
file_ext =~ /swf/i
end
@@ -765,7 +747,6 @@ class Post < ApplicationRecord
return tags if !Danbooru.config.enable_dimension_autotagging
tags -= %w(incredibly_absurdres absurdres highres lowres huge_filesize flash webm mp4)
tags -= %w(animated_gif animated_png) if new_record?
if has_dimensions?
if image_width >= 10_000 || image_height >= 10_000
@@ -794,14 +775,6 @@ class Post < ApplicationRecord
tags << "huge_filesize"
end
if is_animated_gif?
tags << "animated_gif"
end
if is_animated_png?
tags << "animated_png"
end
if is_flash?
tags << "flash"
end

View File

@@ -80,10 +80,14 @@ class Upload < ApplicationRecord
end
end
def tag_audio
if is_video? && video.audio_channels.present?
self.tag_string = "#{tag_string} video_with_sound"
end
def automatic_tags
return "" unless Danbooru.config.enable_dimension_autotagging
tags = []
tags << "video_with_sound" if is_video_with_audio?
tags << "animated_gif" if is_animated_gif?
tags << "animated_png" if is_animated_png?
tags.join(" ")
end
def validate_video_duration
@@ -109,9 +113,9 @@ class Upload < ApplicationRecord
calculate_hash(file_path)
validate_md5_uniqueness
validate_md5_confirmation
tag_audio
validate_video_duration
calculate_file_size(file_path)
self.tag_string = "#{tag_string} #{automatic_tags}"
self.image_width, self.image_height = calculate_dimensions
generate_resizes(file_path)
move_file
@@ -219,9 +223,21 @@ class Upload < ApplicationRecord
%w(webm mp4).include?(file_ext)
end
def is_video_with_audio?
is_video? && video.audio_channels.present?
end
def is_ugoira?
%w(zip).include?(file_ext)
end
def is_animated_gif?
file_ext == "gif" && Magick::Image.ping(file_path).length > 1
end
def is_animated_png?
file_ext == "png" && APNGInspector.new(file_path).inspect!.animated?
end
end
module ResizerMethods