Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LIBAVALON-106. Set default thumbnail for videos #82

Open
wants to merge 2 commits into
base: avalon-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/models/master_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,18 @@ def update_derivatives(outputs, managed = true)
save
end

def set_default_thumbnail
if is_video?
thumbnail.content=StringIO.new(File.read('app/assets/images/video_icon.png', encoding: 'BINARY'))
thumbnail.mime_type='image/png'
thumbnail.original_name='video_icon.png'
thumbnail.save
save
reload
thumbnail.reload
end
end

alias_method :'_poster_offset', :'poster_offset'
def poster_offset
_poster_offset.to_i
Expand Down Expand Up @@ -387,6 +399,7 @@ def extract_still(options={})
unless options[:preview]
file.mime_type = 'image/jpeg'
file.content = StringIO.new(result)
file.original_name = 'thumbnail.jpg' if type == 'thumbnail'
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions app/services/master_file_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def self.from_specs(media_object, specs)
if master_file.save
media_object.save
master_file.process

# Replace thumbnail (for videos) with default thumbnail
master_file.set_default_thumbnail

response[:master_files] << master_file
else
response[:flash][:error] << "There was a problem storing the file"
Expand Down
3 changes: 3 additions & 0 deletions lib/avalon/batch/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ def process!
master_file.media_object = media_object
media_object.save
master_file.process(files)

# Replace thumbnail (for videos) with default thumbnail
master_file.set_default_thumbnail
else
Rails.logger.error "Problem saving MasterFile(#{master_file.id}): #{master_file.errors.full_messages.to_sentence}"
end
Expand Down
12 changes: 6 additions & 6 deletions spec/controllers/master_files_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ class << file

it "returns thumbnail" do
get :get_frame, params: { id: mf.id, type: 'thumbnail', size: 'bar' }
expect(response.body).to eq('fake image content')
expect(response.headers['Content-Type']).to eq('image/jpeg')
# get_frame returns default "video_icon.png"
expect(response.headers['Content-Type']).to eq('image/png')
end

it "returns offset thumbnail" do
Expand Down Expand Up @@ -645,10 +645,10 @@ class << file

describe "#update" do
let(:master_file) { FactoryBot.create(:master_file, :with_media_object) }
subject { put('update', params: { id: master_file.id,
master_file: { title: "New label",
poster_offset: "00:00:03",
date_digitized: "2020-08-27",
subject { put('update', params: { id: master_file.id,
master_file: { title: "New label",
poster_offset: "00:00:03",
date_digitized: "2020-08-27",
permalink: "https://perma.link" }})}

before do
Expand Down
3 changes: 1 addition & 2 deletions spec/factories/master_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@
end
trait :with_thumbnail do
after(:create) do |mf|
mf.thumbnail.mime_type = 'image/jpeg'
mf.thumbnail.content = 'fake image content'
mf.set_default_thumbnail
mf.save
end
end
Expand Down
15 changes: 12 additions & 3 deletions spec/models/master_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,18 @@
end

describe 'thumbnail' do
let(:master_file) { FactoryBot.create(:master_file) }
it 'sets original_name to default value' do
expect(master_file.thumbnail.original_name).to eq 'thumbnail.jpg'
let(:master_file) { FactoryBot.create(:master_file, :with_thumbnail) }
it 'uses a default icon for videos' do
expect(master_file.thumbnail.original_name).to eq 'video_icon.png'
end
it 'uses a default icon for audio' do
master_file.file_format = 'Sound'
master_file.set_workflow
master_file.thumbnail.original_name = 'audio_icon.png'

# Setting default thumbnail should not change the current thumbnail
master_file.set_default_thumbnail
expect(master_file.thumbnail.original_name).to eq 'audio_icon.png'
end
end

Expand Down