mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 20:44:40 +08:00
FEATURE: Support Spotify Onebox (#27540)
This commit is contained in:

committed by
GitHub

parent
604ca4d46e
commit
b2a9676f0b
31
lib/onebox/engine/spotify_onebox.rb
Normal file
31
lib/onebox/engine/spotify_onebox.rb
Normal 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
|
Reference in New Issue
Block a user