parent
6861534d9c
commit
5432edb5a7
@ -27,13 +27,15 @@ class CustomEmoji < ApplicationRecord
|
|||||||
:(#{SHORTCODE_RE_FRAGMENT}):
|
:(#{SHORTCODE_RE_FRAGMENT}):
|
||||||
(?=[^[:alnum:]:]|$)/x
|
(?=[^[:alnum:]:]|$)/x
|
||||||
|
|
||||||
|
IMAGE_MIME_TYPES = %w(image/png image/gif image/webp).freeze
|
||||||
|
|
||||||
has_one :local_counterpart, -> { where(domain: nil) }, class_name: 'CustomEmoji', primary_key: :shortcode, foreign_key: :shortcode
|
has_one :local_counterpart, -> { where(domain: nil) }, class_name: 'CustomEmoji', primary_key: :shortcode, foreign_key: :shortcode
|
||||||
|
|
||||||
has_attached_file :image, styles: { static: { format: 'png', convert_options: '-coalesce -strip' } }
|
has_attached_file :image, styles: { static: { format: 'png', convert_options: '-coalesce -strip' } }
|
||||||
|
|
||||||
before_validation :downcase_domain
|
before_validation :downcase_domain
|
||||||
|
|
||||||
validates_attachment :image, content_type: { content_type: 'image/png' }, presence: true, size: { less_than: LIMIT }
|
validates_attachment :image, content_type: { content_type: IMAGE_MIME_TYPES }, presence: true, size: { less_than: LIMIT }
|
||||||
validates :shortcode, uniqueness: { scope: :domain }, format: { with: /\A#{SHORTCODE_RE_FRAGMENT}\z/ }, length: { minimum: 2 }
|
validates :shortcode, uniqueness: { scope: :domain }, format: { with: /\A#{SHORTCODE_RE_FRAGMENT}\z/ }, length: { minimum: 2 }
|
||||||
|
|
||||||
scope :local, -> { where(domain: nil) }
|
scope :local, -> { where(domain: nil) }
|
||||||
|
Loading…
Reference in New Issue
Block a user