mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 09:28:03 +08:00
Generate thumbnail images for video uploads (#19801)
* FEATURE: Generate thumbnail images for uploaded videos Topics in Discourse have a topic thumbnail feature which allows themes to show a preview image before viewing the actual Topic. This PR allows for the ability to generate a thumbnail image from an uploaded video that can be use for the topic preview.
This commit is contained in:
@ -1531,6 +1531,45 @@ RSpec.describe Post do
|
||||
expect(post.revisions.pluck(:number)).to eq([1, 2])
|
||||
end
|
||||
|
||||
describe "video_thumbnails" do
|
||||
before { SiteSetting.enable_diffhtml_preview = true }
|
||||
|
||||
fab!(:video_upload) { Fabricate(:upload, extension: "mp4") }
|
||||
fab!(:image_upload) { Fabricate(:upload) }
|
||||
fab!(:image_upload_2) { Fabricate(:upload) }
|
||||
let(:base_url) { "#{Discourse.base_url_no_prefix}#{Discourse.base_path}" }
|
||||
let(:video_url) { "#{base_url}#{video_upload.url}" }
|
||||
|
||||
let(:raw_video) { <<~RAW }
|
||||
<video width="100%" height="100%" controls>
|
||||
<source src="#{video_url}">
|
||||
<a href="#{video_url}">#{video_url}</a>
|
||||
</video>
|
||||
RAW
|
||||
|
||||
let(:post) { Fabricate(:post, raw: raw_video) }
|
||||
|
||||
it "has a topic thumbnail" do
|
||||
# Thumbnails are tied to a specific video file by using the
|
||||
# video's sha1 as the image filename
|
||||
image_upload.original_filename = "#{video_upload.sha1}.png"
|
||||
image_upload.save!
|
||||
post.link_post_uploads
|
||||
|
||||
post.topic.reload
|
||||
expect(post.topic.topic_thumbnails.length).to eq(1)
|
||||
end
|
||||
|
||||
it "only applies for video uploads" do
|
||||
image_upload.original_filename = "#{image_upload_2.sha1}.png"
|
||||
image_upload.save!
|
||||
post.link_post_uploads
|
||||
|
||||
post.topic.reload
|
||||
expect(post.topic.topic_thumbnails.length).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
describe "uploads" do
|
||||
fab!(:video_upload) { Fabricate(:upload, extension: "mp4") }
|
||||
fab!(:image_upload) { Fabricate(:upload) }
|
||||
|
Reference in New Issue
Block a user