mirror of https://github.com/tootsuite/mastodon
Move default embed size knowledge into `OEmbedSerializer` (#31990)
Co-authored-by: Claire <claire.github-309c@sitedethib.com>pull/31999/head
parent
8afa3bb2fa
commit
bdf83c353f
|
@ -7,7 +7,7 @@ class Api::OEmbedController < Api::BaseController
|
||||||
before_action :require_public_status!
|
before_action :require_public_status!
|
||||||
|
|
||||||
def show
|
def show
|
||||||
render json: @status, serializer: OEmbedSerializer, width: maxwidth_or_default, height: maxheight_or_default
|
render json: @status, serializer: OEmbedSerializer, width: params[:maxwidth], height: params[:maxheight]
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -23,12 +23,4 @@ class Api::OEmbedController < Api::BaseController
|
||||||
def status_finder
|
def status_finder
|
||||||
StatusFinder.new(params[:url])
|
StatusFinder.new(params[:url])
|
||||||
end
|
end
|
||||||
|
|
||||||
def maxwidth_or_default
|
|
||||||
(params[:maxwidth].presence || 400).to_i
|
|
||||||
end
|
|
||||||
|
|
||||||
def maxheight_or_default
|
|
||||||
params[:maxheight].present? ? params[:maxheight].to_i : nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,7 +9,7 @@ class Api::Web::EmbedsController < Api::Web::BaseController
|
||||||
return not_found if @status.hidden?
|
return not_found if @status.hidden?
|
||||||
|
|
||||||
if @status.local?
|
if @status.local?
|
||||||
render json: @status, serializer: OEmbedSerializer, width: 400
|
render json: @status, serializer: OEmbedSerializer
|
||||||
else
|
else
|
||||||
return not_found unless user_signed_in?
|
return not_found unless user_signed_in?
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@ class OEmbedSerializer < ActiveModel::Serializer
|
||||||
div1: 'font-weight: 500;',
|
div1: 'font-weight: 500;',
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
|
DEFAULT_WIDTH = 400
|
||||||
|
|
||||||
include RoutingHelper
|
include RoutingHelper
|
||||||
include ActionView::Helpers::TagHelper
|
include ActionView::Helpers::TagHelper
|
||||||
|
|
||||||
|
@ -57,10 +59,10 @@ class OEmbedSerializer < ActiveModel::Serializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def width
|
def width
|
||||||
instance_options[:width]
|
(instance_options[:width] || DEFAULT_WIDTH).to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
def height
|
def height
|
||||||
instance_options[:height]
|
instance_options[:height].presence&.to_i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue