From bd5ad304bac69b34a3c223e9baac532106db7dd8 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 17 Sep 2016 17:47:26 +0200 Subject: [PATCH] Adding media controller, 1 webm/compose form allowed, previews generated --- .../components/components/status.jsx | 3 ++- .../components/components/upload_form.jsx | 4 +++- .../components/features/status/index.jsx | 18 ++++++++++++++++-- app/controllers/media_controller.rb | 13 +++++++++++++ app/models/media_attachment.rb | 6 +++++- app/views/api/media/create.rabl | 3 ++- config/routes.rb | 1 + 7 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 app/controllers/media_controller.rb diff --git a/app/assets/javascripts/components/components/status.jsx b/app/assets/javascripts/components/components/status.jsx index 3882fc97fd..8cdbd5625d 100644 --- a/app/assets/javascripts/components/components/status.jsx +++ b/app/assets/javascripts/components/components/status.jsx @@ -40,8 +40,9 @@ const Status = React.createClass({ if (e.button === 0) { e.preventDefault(); hashHistory.push(`/accounts/${id}`); - e.stopPropagation(); } + + e.stopPropagation(); }, render () { diff --git a/app/assets/javascripts/components/components/upload_form.jsx b/app/assets/javascripts/components/components/upload_form.jsx index 429e672c08..f0b6f7992e 100644 --- a/app/assets/javascripts/components/components/upload_form.jsx +++ b/app/assets/javascripts/components/components/upload_form.jsx @@ -25,9 +25,11 @@ const UploadForm = React.createClass({ ); }.bind(this)); + const noMoreAllowed = (this.props.media.some(m => m.get('type') === 'video')) || (this.props.media.size > 3); + return (
- 3} /> +
{uploads} diff --git a/app/assets/javascripts/components/features/status/index.jsx b/app/assets/javascripts/components/features/status/index.jsx index 122db8906f..39bc2bec59 100644 --- a/app/assets/javascripts/components/features/status/index.jsx +++ b/app/assets/javascripts/components/features/status/index.jsx @@ -4,6 +4,8 @@ import ImmutablePropTypes from 'react-immutable-proptypes'; import { fetchStatus } from '../../actions/statuses'; import Immutable from 'immutable'; import EmbeddedStatus from '../../components/status'; +import { favourite, reblog } from '../../actions/interactions'; +import { replyCompose } from '../../actions/compose'; function selectStatus(state, id) { let status = state.getIn(['timelines', 'statuses', id]); @@ -49,8 +51,20 @@ const Status = React.createClass({ } }, + handleFavouriteClick (status) { + this.props.dispatch(favourite(status)); + }, + + handleReplyClick (status) { + this.props.dispatch(replyCompose(status)); + }, + + handleReblogClick (status) { + this.props.dispatch(reblog(status)); + }, + renderChildren (list) { - return list.map(s => ); + return list.map(s => ); }, render () { @@ -63,7 +77,7 @@ const Status = React.createClass({ return (
{this.renderChildren(ancestors)} - + {this.renderChildren(descendants)}
); diff --git a/app/controllers/media_controller.rb b/app/controllers/media_controller.rb new file mode 100644 index 0000000000..5a7b0bcbd6 --- /dev/null +++ b/app/controllers/media_controller.rb @@ -0,0 +1,13 @@ +class MediaController < ApplicationController + before_action :set_media_attachment + + def show + redirect TagManager.instance.url_for(@media_attachment.status) + end + + private + + def set_media_attachment + @media_attachment = MediaAttachment.where.not(status_id: nil).find(params[:id]) + end +end diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 7dddfd6106..73fb967c47 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -5,7 +5,7 @@ class MediaAttachment < ApplicationRecord belongs_to :account, inverse_of: :media_attachments belongs_to :status, inverse_of: :media_attachments - has_attached_file :file, styles: lambda { |f| f.instance.image? ? { small: '510x680>' } : { small: { format: 'webm' } } }, processors: lambda { |f| f.video? ? [:transcoder] : [:thumbnail] } + has_attached_file :file, styles: lambda { |f| f.instance.image? ? { small: '510x680>' } : { small: { convert_options: { output: { vf: 'scale="min(510\, iw):min(680\, ih)":force_original_aspect_ratio=decrease' } }, format: 'png', time: 1 } } }, processors: lambda { |f| f.video? ? [:transcoder] : [:thumbnail] } validates_attachment_content_type :file, content_type: IMAGE_MIME_TYPES + VIDEO_MIME_TYPES validates_attachment_size :file, less_than: 4.megabytes @@ -26,4 +26,8 @@ class MediaAttachment < ApplicationRecord def video? VIDEO_MIME_TYPES.include? file_content_type end + + def type + image? ? 'image' : 'video' + end end diff --git a/app/views/api/media/create.rabl b/app/views/api/media/create.rabl index 0239aa585d..803a930944 100644 --- a/app/views/api/media/create.rabl +++ b/app/views/api/media/create.rabl @@ -1,4 +1,5 @@ object @media -attribute :id +attribute :id, :type node(:url) { |media| full_asset_url(media.file.url) } node(:preview_url) { |media| full_asset_url(media.file.url(:small)) } +node(:text_url) { |media| medium_url(media) } diff --git a/config/routes.rb b/config/routes.rb index 4a863a2c1a..1232f8a442 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -30,6 +30,7 @@ Rails.application.routes.draw do end resource :settings, only: [:show, :update] + resources :media, only: [:show] namespace :api do # PubSubHubbub