From 480a83e843b92cc1fa4378b576bfd173024f3f8c Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 19 Jun 2019 23:42:38 +0200 Subject: port tootsuite#11123 to monsterfork: Add audio uploads * Add audio uploads Fix #4827 Accept uploads of OGG, WAV, FLAC, OPUS and MP3 files, and converts them to OGG. Media attachments get a new `audio` type. In the UI, audio uploads are displayed identically to video uploads. * Improve code style --- app/controllers/media_controller.rb | 12 +++- app/javascript/mastodon/components/status.js | 12 ++-- .../features/compose/components/upload_button.js | 8 ++- .../compose/containers/upload_button_container.js | 2 +- .../features/status/components/detailed_status.js | 12 ++-- app/javascript/mastodon/locales/en.json | 2 +- app/models/media_attachment.rb | 80 +++++++++++++--------- app/serializers/initial_state_serializer.rb | 2 +- app/services/post_status_service.rb | 2 +- app/views/statuses/_detailed_status.html.haml | 2 +- app/views/statuses/_simple_status.html.haml | 2 +- 11 files changed, 80 insertions(+), 56 deletions(-) diff --git a/app/controllers/media_controller.rb b/app/controllers/media_controller.rb index 352a04c54..05cf09c28 100644 --- a/app/controllers/media_controller.rb +++ b/app/controllers/media_controller.rb @@ -9,6 +9,8 @@ class MediaController < ApplicationController before_action :authenticate_user!, if: :whitelist_mode? before_action :set_media_attachment before_action :verify_permitted_status! + before_action :check_playable, only: :player + before_action :allow_iframing, only: :player content_security_policy only: :player do |p| p.frame_ancestors(false) @@ -20,8 +22,6 @@ class MediaController < ApplicationController def player @body_classes = 'player' - response.headers['X-Frame-Options'] = 'ALLOWALL' - raise ActiveRecord::RecordNotFound unless @media_attachment.video? || @media_attachment.gifv? end private @@ -35,4 +35,12 @@ class MediaController < ApplicationController rescue Mastodon::NotPermittedError raise ActiveRecord::RecordNotFound end + + def check_playable + not_found unless @media_attachment.larger_media_format? + end + + def allow_iframing + response.headers['X-Frame-Options'] = 'ALLOWALL' + end end diff --git a/app/javascript/mastodon/components/status.js b/app/javascript/mastodon/components/status.js index f74e2acce..40f184583 100644 --- a/app/javascript/mastodon/components/status.js +++ b/app/javascript/mastodon/components/status.js @@ -327,17 +327,17 @@ class Status extends ImmutablePureComponent { media={status.get('media_attachments')} /> ); - } else if (status.getIn(['media_attachments', 0, 'type']) === 'video') { - const video = status.getIn(['media_attachments', 0]); + } else if (['video', 'audio'].includes(status.getIn(['media_attachments', 0, 'type']))) { + const attachment = status.getIn(['media_attachments', 0]); media = ( {Component => ( { const mapStateToProps = state => ({ acceptContentTypes: state.getIn(['media_attachments', 'accept_content_types']), @@ -60,9 +62,9 @@ class UploadButton extends ImmutablePureComponent { return (
- +