From bb71538bb503159177d46d8956bd466973c0876b Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 28 Jul 2018 19:25:33 +0200 Subject: Redesign public profiles and toots (#8068) --- app/models/concerns/account_header.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/concerns/account_header.rb b/app/models/concerns/account_header.rb index ef40b8126..067e166eb 100644 --- a/app/models/concerns/account_header.rb +++ b/app/models/concerns/account_header.rb @@ -5,11 +5,12 @@ module AccountHeader IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif'].freeze LIMIT = 2.megabytes + MAX_PIXELS = 750_000 # 1500x500px class_methods do def header_styles(file) - styles = { original: { geometry: '700x335#', file_geometry_parser: FastGeometryParser } } - styles[:static] = { geometry: '700x335#', format: 'png', convert_options: '-coalesce', file_geometry_parser: FastGeometryParser } if file.content_type == 'image/gif' + styles = { original: { pixels: MAX_PIXELS, file_geometry_parser: FastGeometryParser } } + styles[:static] = { format: 'png', convert_options: '-coalesce', file_geometry_parser: FastGeometryParser } if file.content_type == 'image/gif' styles end -- cgit From 16566635985cfeb4586196eaca953032eebaa00f Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 30 Jul 2018 19:33:05 +0200 Subject: Convert MOV and WEBM to MP4, raise maximum limit to 40MB (#8101) Separate size limits for images and video. Images remain at 8MB, while videos can be up to 40MB. --- app/models/media_attachment.rb | 54 +++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 22 deletions(-) (limited to 'app/models') diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 63c6d5af8..1e4fae3de 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -25,10 +25,11 @@ class MediaAttachment < ApplicationRecord enum type: [:image, :gifv, :video, :unknown] IMAGE_FILE_EXTENSIONS = ['.jpg', '.jpeg', '.png', '.gif'].freeze - VIDEO_FILE_EXTENSIONS = ['.webm', '.mp4', '.m4v'].freeze + VIDEO_FILE_EXTENSIONS = ['.webm', '.mp4', '.m4v', '.mov'].freeze - IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif'].freeze - VIDEO_MIME_TYPES = ['video/webm', 'video/mp4'].freeze + IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif'].freeze + VIDEO_MIME_TYPES = ['video/webm', 'video/mp4', 'video/quicktime'].freeze + VIDEO_CONVERTIBLE_MIME_TYPES = ['video/webm', 'video/quicktime'].freeze IMAGE_STYLES = { original: { @@ -54,7 +55,25 @@ class MediaAttachment < ApplicationRecord }, }.freeze - LIMIT = 8.megabytes + VIDEO_FORMAT = { + format: 'mp4', + convert_options: { + output: { + 'movflags' => 'faststart', + 'pix_fmt' => 'yuv420p', + 'vf' => 'scale=\'trunc(iw/2)*2:trunc(ih/2)*2\'', + 'vsync' => 'cfr', + 'c:v' => 'h264', + 'b:v' => '500K', + 'maxrate' => '1300K', + 'bufsize' => '1300K', + 'crf' => 18, + }, + }, + }.freeze + + IMAGE_LIMIT = 8.megabytes + VIDEO_LIMIT = 40.megabytes belongs_to :account, inverse_of: :media_attachments, optional: true belongs_to :status, inverse_of: :media_attachments, optional: true @@ -65,8 +84,9 @@ class MediaAttachment < ApplicationRecord convert_options: { all: '-quality 90 -strip' } validates_attachment_content_type :file, content_type: IMAGE_MIME_TYPES + VIDEO_MIME_TYPES - validates_attachment_size :file, less_than: LIMIT - remotable_attachment :file, LIMIT + validates_attachment_size :file, less_than: IMAGE_LIMIT, unless: :video? + validates_attachment_size :file, less_than: VIDEO_LIMIT, if: :video? + remotable_attachment :file, VIDEO_LIMIT include Attachmentable @@ -122,25 +142,15 @@ class MediaAttachment < ApplicationRecord if f.instance.file_content_type == 'image/gif' { small: IMAGE_STYLES[:small], - original: { - format: 'mp4', - convert_options: { - output: { - 'movflags' => 'faststart', - 'pix_fmt' => 'yuv420p', - 'vf' => 'scale=\'trunc(iw/2)*2:trunc(ih/2)*2\'', - 'vsync' => 'cfr', - 'c:v' => 'h264', - 'b:v' => '500K', - 'maxrate' => '1300K', - 'bufsize' => '1300K', - 'crf' => 18, - }, - }, - }, + original: VIDEO_FORMAT, } elsif IMAGE_MIME_TYPES.include? f.instance.file_content_type IMAGE_STYLES + elsif VIDEO_CONVERTIBLE_MIME_TYPES.include?(f.instance.file_content_type) + { + small: VIDEO_STYLES[:small], + original: VIDEO_FORMAT, + } else VIDEO_STYLES end -- cgit From e7e577dd6e82d9b6ae3afa799a56953d0468deea Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 30 Jul 2018 22:29:52 +0200 Subject: Enforce username format for remote users, too (#8102) Initially I thought there might be valid reasons for remote users to have a different, unpredicted username format. However, I now realize such a difference would be unusable and unexpected within Mastodon. Fix #8058 --- app/models/account.rb | 1 + spec/models/account_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/account.rb b/app/models/account.rb index 1f720bf88..0272b4615 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -68,6 +68,7 @@ class Account < ApplicationRecord # Remote user validations validates :username, uniqueness: { scope: :domain, case_sensitive: true }, if: -> { !local? && will_save_change_to_username? } + validates :username, format: { with: /\A#{USERNAME_RE}\z/i }, if: -> { !local? && will_save_change_to_username? } # Local user validations validates :username, format: { with: /\A[a-z0-9_]+\z/i }, length: { maximum: 30 }, if: -> { local? && will_save_change_to_username? } diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index c50791bcd..ec01026db 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -618,10 +618,10 @@ RSpec.describe Account, type: :model do expect(account).not_to model_have_error_on_field(:username) end - it 'is valid even if the username doesn\'t only contains letters, numbers and underscores' do + it 'is invalid if the username doesn\'t only contains letters, numbers and underscores' do account = Fabricate.build(:account, domain: 'domain', username: 'the-doctor') account.valid? - expect(account).not_to model_have_error_on_field(:username) + expect(account).to model_have_error_on_field(:username) end it 'is valid even if the username is longer then 30 characters' do -- cgit