mirror of
https://github.com/discourse/discourse.git
synced 2025-02-24 10:31:54 +08:00
FEATURE: Handle newer url format for Twitch clips (#31080)
This commit is contained in:
parent
8ca2c14874
commit
68dde7887a
@ -4,7 +4,7 @@ require_relative "../mixins/twitch_onebox"
|
||||
|
||||
class Onebox::Engine::TwitchClipsOnebox
|
||||
def self.twitch_regexp
|
||||
%r{^https?://clips\.twitch\.tv/([a-zA-Z0-9_]+/?[^#\?/]+)}
|
||||
%r{^https?://(?:clips\.twitch\.tv/embed\?clip=|www\.twitch\.tv/[a-zA-Z0-9_]+/clip/|clips\.twitch\.tv/)([a-zA-Z0-9_\-]+)}
|
||||
end
|
||||
|
||||
include Onebox::Mixins::TwitchOnebox
|
||||
|
@ -3,10 +3,33 @@
|
||||
RSpec.describe Onebox::Engine::TwitchClipsOnebox do
|
||||
let(:hostname) { Discourse.current_hostname }
|
||||
let(:options) { { hostname: hostname } }
|
||||
let(:expected) do
|
||||
%r{<iframe src="https://clips\.twitch\.tv/embed\?clip=CheerfulAliveFoxUWot-3FacBI-00c45Ptvd&parent=#{hostname}}
|
||||
end
|
||||
|
||||
it "has the iframe with the correct channel" do
|
||||
expect(Onebox.preview("https://clips.twitch.tv/FunVastGalagoKlappa", options).to_s).to match(
|
||||
%r{<iframe src="https://clips\.twitch\.tv/embed\?clip=FunVastGalagoKlappa&parent=#{hostname}},
|
||||
)
|
||||
expect(
|
||||
Onebox.preview("https://clips.twitch.tv/CheerfulAliveFoxUWot-3FacBI-00c45Ptvd", options).to_s,
|
||||
).to match(expected)
|
||||
end
|
||||
|
||||
it "handles all possible clips urls" do
|
||||
expect(
|
||||
Onebox.preview(
|
||||
"https://www.twitch.tv/gorgc/clip/CheerfulAliveFoxUWot-3FacBI-00c45Ptvd?filter=clips&range=7d&sort=time",
|
||||
options,
|
||||
).to_s,
|
||||
).to match(expected)
|
||||
|
||||
expect(
|
||||
Onebox.preview(
|
||||
"https://clips.twitch.tv/embed?clip=CheerfulAliveFoxUWot-3FacBI-00c45Ptvd&parent=www.example.com",
|
||||
options,
|
||||
).to_s,
|
||||
).to match(expected)
|
||||
|
||||
expect(
|
||||
Onebox.preview("https://clips.twitch.tv/CheerfulAliveFoxUWot-3FacBI-00c45Ptvd", options).to_s,
|
||||
).to match(expected)
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user