Add tootctl command for set custom emoji size if not set
This commit is contained in:
parent
2cdaf2af76
commit
a319dbb7d5
2 changed files with 28 additions and 6 deletions
|
@ -56,7 +56,7 @@ class CustomEmoji < ApplicationRecord
|
||||||
|
|
||||||
after_commit :remove_entity_cache
|
after_commit :remove_entity_cache
|
||||||
|
|
||||||
after_post_process :set_size
|
after_post_process :set_post_size
|
||||||
|
|
||||||
def local?
|
def local?
|
||||||
domain.nil?
|
domain.nil?
|
||||||
|
@ -76,6 +76,10 @@ class CustomEmoji < ApplicationRecord
|
||||||
shortcode
|
shortcode
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_size
|
||||||
|
set_size(image)
|
||||||
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def from_text(text, domain = nil)
|
def from_text(text, domain = nil)
|
||||||
return [] if text.blank?
|
return [] if text.blank?
|
||||||
|
@ -102,14 +106,17 @@ class CustomEmoji < ApplicationRecord
|
||||||
self.domain = domain.downcase unless domain.nil?
|
self.domain = domain.downcase unless domain.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_size
|
def set_post_size
|
||||||
image.queued_for_write.each do |style, file|
|
image.queued_for_write.each do |style, file|
|
||||||
if style == :original
|
if style == :original
|
||||||
image_size = FastImage.size(file.path)
|
set_size(file)
|
||||||
self.image_width = image_size[0]
|
|
||||||
self.image_height = image_size[1]
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_size(file)
|
||||||
|
image_size = FastImage.size(file.path)
|
||||||
|
self.image_width = image_size[0]
|
||||||
|
self.image_height = image_size[1]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -132,6 +132,21 @@ module Mastodon
|
||||||
say('OK', :green)
|
say('OK', :green)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc 'size', 'Set custom emojis width/height'
|
||||||
|
long_desc <<-LONG_DESC
|
||||||
|
Set custom emojis width/height if width/height is nil or zero.
|
||||||
|
LONG_DESC
|
||||||
|
def size
|
||||||
|
scope = CustomEmoji.where(image_width: nil).or(CustomEmoji.where(image_height: [0, nil]))
|
||||||
|
size = scope.size
|
||||||
|
count = 0
|
||||||
|
scope.find_each do |emoji|
|
||||||
|
emoji.update_size
|
||||||
|
count += 1
|
||||||
|
say("(#{count}/#{size}) proceed #{emoji.shortcode}@#{emoji.domain}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def color(green, _yellow, red)
|
def color(green, _yellow, red)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue