Fix #431 - convert gif to webm during upload. Web UI treats them like it did
before. In the API, attachments now can be either image, video or gifv. Gifv is to be treated like images in terms of behaviour, but are videos by file type.master
parent
4cbeb9a7eb
commit
caf5b8e975
@ -0,0 +1,21 @@ |
||||
import PureRenderMixin from 'react-addons-pure-render-mixin'; |
||||
|
||||
const ExtendedVideoPlayer = React.createClass({ |
||||
|
||||
propTypes: { |
||||
src: React.PropTypes.string.isRequired |
||||
}, |
||||
|
||||
mixins: [PureRenderMixin], |
||||
|
||||
render () { |
||||
return ( |
||||
<div> |
||||
<video src={this.props.src} autoPlay muted loop /> |
||||
</div> |
||||
); |
||||
}, |
||||
|
||||
}); |
||||
|
||||
export default ExtendedVideoPlayer; |
@ -0,0 +1,4 @@ |
||||
.media-item |
||||
= link_to media.remote_url.blank? ? media.file.url(:original) : media.remote_url, style: media.image? ? "background-image: url(#{media.file.url(:original)})" : "", target: '_blank', rel: 'noopener', class: "u-#{media.video? || media.gifv? ? 'video' : 'photo'}" do |
||||
- unless media.image? |
||||
%video{ src: media.file.url(:original), autoplay: true, loop: true }/ |
@ -0,0 +1,12 @@ |
||||
class AddTypeToMediaAttachments < ActiveRecord::Migration[5.0] |
||||
def up |
||||
add_column :media_attachments, :type, :integer, default: 0, null: false |
||||
|
||||
MediaAttachment.where(file_content_type: MediaAttachment::IMAGE_MIME_TYPES).update_all(type: MediaAttachment.types[:image]) |
||||
MediaAttachment.where(file_content_type: MediaAttachment::VIDEO_MIME_TYPES).update_all(type: MediaAttachment.types[:video]) |
||||
end |
||||
|
||||
def down |
||||
remove_column :media_attachments, :type |
||||
end |
||||
end |
@ -0,0 +1,21 @@ |
||||
# frozen_string_literal: true |
||||
|
||||
module Paperclip |
||||
# This transcoder is only to be used for the MediaAttachment model |
||||
# to convert animated gifs to webm |
||||
class GifTranscoder < Paperclip::Processor |
||||
def make |
||||
num_frames = identify('-format %n :file', file: file.path).to_i |
||||
|
||||
return file unless options[:style] == :original && num_frames > 1 |
||||
|
||||
final_file = Paperclip::Transcoder.make(file, options, attachment) |
||||
|
||||
attachment.instance.file_file_name = 'media.webm' |
||||
attachment.instance.file_content_type = 'video/webm' |
||||
attachment.instance.type = MediaAttachment.types[:gifv] |
||||
|
||||
final_file |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue