FIX: Video thumbnails for missing videos (#28152)

Skip trying to find a thumbnail if the video src cannot be found.

Bug report: https://meta.discourse.org/t/317423
This commit is contained in:
Blake Erickson
2024-07-31 10:54:52 -06:00
committed by GitHub
parent fa6dbbed1b
commit 30048ab97f
2 changed files with 39 additions and 0 deletions

View File

@ -2794,4 +2794,42 @@ HTML
require("discourse-common/lib/deprecated").default("Some deprecation message");
JS
end
describe "video thumbnails" do
before do
SiteSetting.authorized_extensions = "mp4|png"
@video_upload = Fabricate(:upload, original_filename: "video.mp4", extension: "mp4")
end
after { Upload.where(original_filename: ["404.png", "#{@video_upload.sha1}.png"]).destroy_all }
it "does not link to a thumbnail image if the video source is missing" do
Fabricate(:upload, original_filename: "404.png", extension: "png")
html = <<~HTML
<p></p><div class="video-placeholder-container" data-video-src="/404"></div><p></p>
HTML
doc = Nokogiri::HTML5.fragment(html)
described_class.add_video_placeholder_image(doc)
expect(doc.to_html).to eq(html)
end
it "links to a thumbnail image if the video source is valid" do
thumbnail =
Fabricate(:upload, original_filename: "#{@video_upload.sha1}.png", extension: "png")
html = <<~HTML
<p></p><div class="video-placeholder-container" data-video-src="#{@video_upload.url}"></div><p></p>
HTML
doc = Nokogiri::HTML5.fragment(html)
described_class.add_video_placeholder_image(doc)
html_with_thumbnail = <<~HTML
<p></p><div class="video-placeholder-container" data-video-src="#{@video_upload.url}" data-thumbnail-src="http://test.localhost#{thumbnail.url}"></div><p></p>
HTML
expect(doc.to_html).to eq(html_with_thumbnail)
end
end
end