1
0
Fork 0
forked from gitea/nas

Change timing to get image size

This commit is contained in:
KMY 2023-03-22 22:50:18 +09:00
parent 2eae1bb9bf
commit 2cdaf2af76
2 changed files with 13 additions and 6 deletions

View file

@ -1,7 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
require 'fastimage'
module Admin module Admin
class CustomEmojisController < BaseController class CustomEmojisController < BaseController
def index def index
@ -20,11 +18,7 @@ module Admin
def create def create
authorize :custom_emoji, :create? authorize :custom_emoji, :create?
image_size = FastImage.size(params[:custom_emoji][:image])
@custom_emoji = CustomEmoji.new(resource_params) @custom_emoji = CustomEmoji.new(resource_params)
@custom_emoji.image_width = image_size[0]
@custom_emoji.image_height = image_size[1]
if @custom_emoji.save if @custom_emoji.save
log_action :create, @custom_emoji log_action :create, @custom_emoji

View file

@ -56,6 +56,8 @@ class CustomEmoji < ApplicationRecord
after_commit :remove_entity_cache after_commit :remove_entity_cache
after_post_process :set_size
def local? def local?
domain.nil? domain.nil?
end end
@ -99,4 +101,15 @@ class CustomEmoji < ApplicationRecord
def downcase_domain def downcase_domain
self.domain = domain.downcase unless domain.nil? self.domain = domain.downcase unless domain.nil?
end end
def set_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
end
end
end
end end