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:
parent
fa6dbbed1b
commit
30048ab97f
|
@ -452,6 +452,7 @@ module PrettyText
|
|||
.css(".video-placeholder-container")
|
||||
.each do |video|
|
||||
video_src = video["data-video-src"]
|
||||
next if video_src == "/404" || video_src.nil?
|
||||
video_sha1 = File.basename(video_src, File.extname(video_src))
|
||||
thumbnail = Upload.where("original_filename LIKE ?", "#{video_sha1}.%").last
|
||||
if thumbnail
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue