Add custom emoji size recording and publish api
This commit is contained in:
parent
47bedd20ca
commit
92df4674ff
6 changed files with 36 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'fastimage'
|
||||
|
||||
module Admin
|
||||
class CustomEmojisController < BaseController
|
||||
def index
|
||||
|
@ -18,7 +20,11 @@ module Admin
|
|||
def create
|
||||
authorize :custom_emoji, :create?
|
||||
|
||||
image_size = FastImage.size(params[:custom_emoji][:image])
|
||||
|
||||
@custom_emoji = CustomEmoji.new(resource_params)
|
||||
@custom_emoji.image_width = image_size[0]
|
||||
@custom_emoji.image_height = image_size[1]
|
||||
|
||||
if @custom_emoji.save
|
||||
log_action :create, @custom_emoji
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
# visible_in_picker :boolean default(TRUE), not null
|
||||
# category_id :bigint(8)
|
||||
# image_storage_schema_version :integer
|
||||
# image_width :integer
|
||||
# image_height :integer
|
||||
#
|
||||
|
||||
class CustomEmoji < ApplicationRecord
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
class REST::CustomEmojiSerializer < ActiveModel::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :shortcode, :url, :static_url, :visible_in_picker
|
||||
attributes :shortcode, :url, :static_url, :visible_in_picker, :width, :height
|
||||
|
||||
attribute :category, if: :category_loaded?
|
||||
|
||||
|
@ -22,4 +22,12 @@ class REST::CustomEmojiSerializer < ActiveModel::Serializer
|
|||
def category_loaded?
|
||||
object.association(:category).loaded? && object.category.present?
|
||||
end
|
||||
|
||||
def width
|
||||
object.image_width
|
||||
end
|
||||
|
||||
def height
|
||||
object.image_height
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,6 +9,8 @@ class REST::EmojiReactionsGroupedByNameSerializer < ActiveModel::Serializer
|
|||
attribute :url, if: :custom_emoji?
|
||||
attribute :static_url, if: :custom_emoji?
|
||||
attribute :domain, if: :custom_emoji?
|
||||
attribute :width, if: :custom_emoji?
|
||||
attribute :height, if: :custom_emoji?
|
||||
attribute :account_ids, if: :account_ids?
|
||||
|
||||
def current_user?
|
||||
|
@ -34,4 +36,12 @@ class REST::EmojiReactionsGroupedByNameSerializer < ActiveModel::Serializer
|
|||
def domain
|
||||
object.custom_emoji.domain
|
||||
end
|
||||
|
||||
def width
|
||||
object.custom_emoji.image_width
|
||||
end
|
||||
|
||||
def height
|
||||
object.custom_emoji.image_height
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
class AddImageSizeToCustomEmojis < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :custom_emojis, :image_width, :integer
|
||||
add_column :custom_emojis, :image_height, :integer
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2023_02_23_102416) do
|
||||
ActiveRecord::Schema.define(version: 2023_03_08_061833) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -338,6 +338,8 @@ ActiveRecord::Schema.define(version: 2023_02_23_102416) do
|
|||
t.boolean "visible_in_picker", default: true, null: false
|
||||
t.bigint "category_id"
|
||||
t.integer "image_storage_schema_version"
|
||||
t.integer "image_width"
|
||||
t.integer "image_height"
|
||||
t.index ["shortcode", "domain"], name: "index_custom_emojis_on_shortcode_and_domain", unique: true
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue