From a319dbb7d5a40acd0eeefb0cacb74a0fc4e27f0b Mon Sep 17 00:00:00 2001 From: KMY Date: Thu, 23 Mar 2023 07:23:39 +0900 Subject: [PATCH] Add tootctl command for set custom emoji size if not set --- app/models/custom_emoji.rb | 19 +++++++++++++------ lib/mastodon/emoji_cli.rb | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/app/models/custom_emoji.rb b/app/models/custom_emoji.rb index ff93d01654..ebf2f195c6 100644 --- a/app/models/custom_emoji.rb +++ b/app/models/custom_emoji.rb @@ -56,7 +56,7 @@ class CustomEmoji < ApplicationRecord after_commit :remove_entity_cache - after_post_process :set_size + after_post_process :set_post_size def local? domain.nil? @@ -76,6 +76,10 @@ class CustomEmoji < ApplicationRecord shortcode end + def update_size + set_size(image) + end + class << self def from_text(text, domain = nil) return [] if text.blank? @@ -102,14 +106,17 @@ class CustomEmoji < ApplicationRecord self.domain = domain.downcase unless domain.nil? end - def set_size + def set_post_size image.queued_for_write.each do |style, file| if style == :original - image_size = FastImage.size(file.path) - self.image_width = image_size[0] - self.image_height = image_size[1] - return + set_size(file) 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 diff --git a/lib/mastodon/emoji_cli.rb b/lib/mastodon/emoji_cli.rb index 88065c2a39..ca079eefb4 100644 --- a/lib/mastodon/emoji_cli.rb +++ b/lib/mastodon/emoji_cli.rb @@ -132,6 +132,21 @@ module Mastodon say('OK', :green) 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 def color(green, _yellow, red)