mirror of
https://github.com/discourse/discourse.git
synced 2024-12-25 19:23:42 +08:00
b2a5f5802a
We have a custom implementation of #symbolize_keys in our Onebox helpers. This is likely a legacy from when Onebox was a standalone gem. This change replaces all usages with either #deep_symbolize_keys from ActiveSupport, or appropriate option to the JSON parser gem used.
48 lines
1.2 KiB
Ruby
48 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Onebox
|
|
module Engine
|
|
class VimeoOnebox
|
|
include Engine
|
|
include StandardEmbed
|
|
|
|
matches_regexp(%r{^https?://(www\.)?vimeo\.com/\d+(/\w+)?/?})
|
|
requires_iframe_origins "https://player.vimeo.com"
|
|
always_https
|
|
|
|
def placeholder_html
|
|
::Onebox::Helpers.video_placeholder_html
|
|
end
|
|
|
|
def to_html
|
|
video_src = Nokogiri::HTML5.fragment(oembed_data[:html]).at_css("iframe")&.[]("src")
|
|
video_src = "https://player.vimeo.com/video/#{oembed_data[:video_id]}" if video_src.blank?
|
|
video_src = video_src.gsub("autoplay=1", "").chomp("?")
|
|
|
|
<<-HTML
|
|
<iframe
|
|
class="vimeo-onebox"
|
|
src="#{video_src}"
|
|
data-original-href="#{link}"
|
|
frameborder="0"
|
|
allowfullscreen
|
|
></iframe>
|
|
HTML
|
|
end
|
|
|
|
private
|
|
|
|
def oembed_data
|
|
response = Onebox::Helpers.fetch_response("https://vimeo.com/api/oembed.json?url=#{url}")
|
|
@oembed_data = ::MultiJson.load(response, symbolize_keys: true)
|
|
rescue StandardError
|
|
"{}"
|
|
end
|
|
|
|
def og_data
|
|
@og_data = get_opengraph
|
|
end
|
|
end
|
|
end
|
|
end
|