From a4fe99b64da7f0f19d77d445bb6b4fb1ccc96bf7 Mon Sep 17 00:00:00 2001 From: PigeonsHouse Date: Mon, 21 Aug 2023 21:47:14 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[update]=20=E3=82=AB=E3=82=B9=E3=82=BF?= =?UTF-8?q?=E3=83=A0=E7=B5=B5=E6=96=87=E5=AD=97=E7=94=B3=E8=AB=8B=E3=81=AE?= =?UTF-8?q?=E4=BB=95=E6=A7=98=E3=82=92v4=E3=81=AE=E3=82=AB=E3=82=B9?= =?UTF-8?q?=E3=82=BF=E3=83=A0=E7=B5=B5=E6=96=87=E5=AD=97=E3=81=AE=E4=BB=95?= =?UTF-8?q?=E6=A7=98=E3=81=AB=E5=90=88=E3=82=8F=E3=81=9B=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/request_custom_emoji.rb | 20 +++++-------------- .../request_custom_emojis/new.html.haml | 2 +- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/app/models/request_custom_emoji.rb b/app/models/request_custom_emoji.rb index 96344088f47f71..d21da0a2a3f123 100644 --- a/app/models/request_custom_emoji.rb +++ b/app/models/request_custom_emoji.rb @@ -19,26 +19,16 @@ class RequestCustomEmoji < ApplicationRecord include Attachmentable - LIMIT = 50.kilobytes - - SHORTCODE_RE_FRAGMENT = '[a-zA-Z0-9_]{2,}' - - SCAN_RE = /(?<=[^[:alnum:]:]|\n|^) - :(#{SHORTCODE_RE_FRAGMENT}): - (?=[^[:alnum:]:]|$)/x - - IMAGE_MIME_TYPES = %w(image/png image/gif).freeze - belongs_to :account - has_attached_file :image, styles: { static: { format: 'png', convert_options: '-coalesce -strip' } }, validate_media_type: false + has_attached_file :image, styles: { static: { format: 'png', convert_options: '-coalesce +profile "!icc,*" +set modify-date +set create-date' } }, validate_media_type: false - validates_attachment :image, content_type: { content_type: IMAGE_MIME_TYPES }, presence: true, size: { less_than: LIMIT } - validates :shortcode, uniqueness: true, format: { with: /\A#{SHORTCODE_RE_FRAGMENT}\z/ }, length: { minimum: 2 } + validates_attachment :image, content_type: { content_type: CustomEmoji::IMAGE_MIME_TYPES }, presence: true, size: { less_than: CustomEmoji::LIMIT } + validates :shortcode, uniqueness: true, format: { with: CustomEmoji::SHORTCODE_ONLY_RE }, length: { minimum: 2 } scope :alphabetic, -> { order(shortcode: :asc) } - remotable_attachment :image, LIMIT + remotable_attachment :image, CustomEmoji::LIMIT def object_type :emoji @@ -48,7 +38,7 @@ class << self def from_text(text, domain = nil) return [] if text.blank? - shortcodes = text.scan(SCAN_RE).map(&:first).uniq + shortcodes = text.scan(CustomEmoji::SCAN_RE).map(&:first).uniq return [] if shortcodes.empty? diff --git a/app/views/settings/request_custom_emojis/new.html.haml b/app/views/settings/request_custom_emojis/new.html.haml index 29559ee1bf465b..e200cd577e1bb4 100644 --- a/app/views/settings/request_custom_emojis/new.html.haml +++ b/app/views/settings/request_custom_emojis/new.html.haml @@ -7,7 +7,7 @@ .fields-group = f.input :shortcode, wrapper: :with_label, label: t('admin.custom_emojis.shortcode'), hint: t('admin.custom_emojis.shortcode_hint') .fields-group - = f.input :image, wrapper: :with_label, input_html: { accept: 'image/png' }, hint: t('admin.custom_emojis.image_hint', size: number_to_human_size(RequestCustomEmoji::LIMIT)) + = f.input :image, wrapper: :with_label, input_html: { accept: CustomEmoji::IMAGE_MIME_TYPES.join(' ') }, hint: t('admin.custom_emojis.image_hint', size: number_to_human_size(CustomEmoji::LIMIT)) .actions = f.button :button, t('settings.request_custom_emoji.upload'), type: :submit From a032051d8855786eb4d212d3fa018ccb7e501e47 Mon Sep 17 00:00:00 2001 From: PigeonsHouse Date: Mon, 21 Aug 2023 21:54:06 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[fix]=20=E9=80=A3=E5=90=88=E9=AF=96?= =?UTF-8?q?=E3=81=AB=E5=AD=98=E5=9C=A8=E3=81=97=E3=81=A6=E3=81=84=E3=82=8B?= =?UTF-8?q?=E3=82=AB=E3=82=B9=E3=82=BF=E3=83=A0=E7=B5=B5=E6=96=87=E5=AD=97?= =?UTF-8?q?=E3=81=AE=E3=82=B7=E3=83=A7=E3=83=BC=E3=83=88=E3=82=B3=E3=83=BC?= =?UTF-8?q?=E3=83=89=E3=81=A8=E3=81=AE=E8=A1=9D=E7=AA=81=E3=82=92=E7=A2=BA?= =?UTF-8?q?=E8=AA=8D=E3=81=97=E3=81=AA=E3=81=84=E3=82=88=E3=81=86=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/settings/request_custom_emojis_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/settings/request_custom_emojis_controller.rb b/app/controllers/settings/request_custom_emojis_controller.rb index c023a9262a9caf..1e02cbe15522b8 100644 --- a/app/controllers/settings/request_custom_emojis_controller.rb +++ b/app/controllers/settings/request_custom_emojis_controller.rb @@ -16,7 +16,7 @@ def new def create @custom_emoji = RequestCustomEmoji.new(resource_params) @custom_emoji.account_id = current_account.id - if CustomEmoji.find_by(shortcode: @custom_emoji.shortcode) + if CustomEmoji.find_by(shortcode: @custom_emoji.shortcode, domain: nil) @custom_emoji.errors.add(:shortcode, I18n.t('settings.request_custom_emoji.errors.already_exists')) render :new return