FEATURE: Handle newer url format for Twitch clips (#31080)

This commit is contained in:
Rafael dos Santos Silva 2025-01-31 10:42:46 -03:00 committed by GitHub
parent 8ca2c14874
commit 68dde7887a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 4 deletions

View File

@ -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

View File

@ -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&amp;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&amp;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