FEATURE: Support Spotify Onebox (#27540)

This commit is contained in:
Rafael dos Santos Silva
2024-06-19 13:27:27 -03:00
committed by GitHub
parent 604ca4d46e
commit b2a9676f0b
4 changed files with 85 additions and 1 deletions

View File

@ -0,0 +1,31 @@
# frozen_string_literal: true
module Onebox
module Engine
class SpotifyOnebox
include Engine
include StandardEmbed
matches_regexp(%r{^https?://open\.spotify/\.com})
requires_iframe_origins "https://open.spotify.com"
always_https
def to_html
oembed = get_oembed
oembed.html
end
def placeholder_html
oembed = get_oembed
return if oembed.thumbnail_url.blank?
"<img src='#{oembed.thumbnail_url}' title='#{oembed.title}' alt='#{oembed.title}' height='#{oembed.thumbnail_height}' width='#{oembed.thumbnail_width}'>"
end
protected
def get_oembed_url
"https://open.spotify.com/oembed?url=#{url}"
end
end
end
end