Merge branch 'master' of https://github.com/tootsuite/mastodon
# Conflicts: # app/controllers/settings/exports_controller.rb # app/models/media_attachment.rb # app/models/status.rb # app/views/about/show.html.haml # docker_entrypoint.sh # spec/views/about/show.html.haml_spec.rb
This commit is contained in:
22
app/models/backup.rb
Normal file
22
app/models/backup.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: backups
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# user_id :integer
|
||||
# dump_file_name :string
|
||||
# dump_content_type :string
|
||||
# dump_file_size :integer
|
||||
# dump_updated_at :datetime
|
||||
# processed :boolean default(FALSE), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class Backup < ApplicationRecord
|
||||
belongs_to :user, inverse_of: :backups
|
||||
|
||||
has_attached_file :dump
|
||||
do_not_validate_attachment_file_type :dump
|
||||
end
|
||||
@@ -7,15 +7,9 @@ module AccountAvatar
|
||||
|
||||
class_methods do
|
||||
def avatar_styles(file)
|
||||
styles = {}
|
||||
geometry = Paperclip::Geometry.from_file(file)
|
||||
|
||||
styles[:original] = '120x120#' if geometry.width != geometry.height || geometry.width > 120 || geometry.height > 120
|
||||
styles[:static] = { format: 'png', convert_options: '-coalesce' } if file.content_type == 'image/gif'
|
||||
|
||||
styles = { original: { geometry: '120x120#', file_geometry_parser: FastGeometryParser } }
|
||||
styles[:static] = { geometry: '120x120#', format: 'png', convert_options: '-coalesce', file_geometry_parser: FastGeometryParser } if file.content_type == 'image/gif'
|
||||
styles
|
||||
rescue Paperclip::Errors::NotIdentifiedByImageMagickError
|
||||
{}
|
||||
end
|
||||
|
||||
private :avatar_styles
|
||||
@@ -23,7 +17,7 @@ module AccountAvatar
|
||||
|
||||
included do
|
||||
# Avatar upload
|
||||
has_attached_file :avatar, styles: ->(f) { avatar_styles(f) }, convert_options: { all: '-strip' }
|
||||
has_attached_file :avatar, styles: ->(f) { avatar_styles(f) }, convert_options: { all: '-strip' }, processors: [:lazy_thumbnail]
|
||||
validates_attachment_content_type :avatar, content_type: IMAGE_MIME_TYPES
|
||||
validates_attachment_size :avatar, less_than: 2.megabytes
|
||||
end
|
||||
|
||||
@@ -7,15 +7,9 @@ module AccountHeader
|
||||
|
||||
class_methods do
|
||||
def header_styles(file)
|
||||
styles = {}
|
||||
geometry = Paperclip::Geometry.from_file(file)
|
||||
|
||||
styles[:original] = '700x335#' unless geometry.width == 700 && geometry.height == 335
|
||||
styles[:static] = { format: 'png', convert_options: '-coalesce' } if file.content_type == 'image/gif'
|
||||
|
||||
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
|
||||
rescue Paperclip::Errors::NotIdentifiedByImageMagickError
|
||||
{}
|
||||
end
|
||||
|
||||
private :header_styles
|
||||
@@ -23,7 +17,7 @@ module AccountHeader
|
||||
|
||||
included do
|
||||
# Header upload
|
||||
has_attached_file :header, styles: ->(f) { header_styles(f) }, convert_options: { all: '-strip' }
|
||||
has_attached_file :header, styles: ->(f) { header_styles(f) }, convert_options: { all: '-strip' }, processors: [:lazy_thumbnail]
|
||||
validates_attachment_content_type :header, content_type: IMAGE_MIME_TYPES
|
||||
validates_attachment_size :header, less_than: 2.megabytes
|
||||
end
|
||||
|
||||
@@ -53,8 +53,11 @@ module Omniauthable
|
||||
private
|
||||
|
||||
def user_params_from_auth(auth)
|
||||
email_is_verified = auth.info.email && (auth.info.verified || auth.info.verified_email)
|
||||
email = auth.info.email if email_is_verified && !User.exists?(email: auth.info.email)
|
||||
strategy = Devise.omniauth_configs[auth.provider.to_sym].strategy
|
||||
assume_verified = strategy.try(:security).try(:assume_email_is_verified)
|
||||
email_is_verified = auth.info.verified || auth.info.verified_email || assume_verified
|
||||
email = auth.info.verified_email || auth.info.email
|
||||
email = email_is_verified && !User.exists?(email: auth.info.email) && email
|
||||
|
||||
{
|
||||
email: email ? email : "#{TEMP_EMAIL_PREFIX}-#{auth.uid}-#{auth.provider}.com",
|
||||
|
||||
@@ -34,7 +34,18 @@ class MediaAttachment < ApplicationRecord
|
||||
VIDEO_MIME_TYPES = ['video/webm', 'video/mp4'].freeze
|
||||
AUDIO_MIME_TYPES = ['audio/mpeg', 'audio/mp4', 'audio/vnd.wav', 'audio/wav', 'audio/x-wav', 'audio/x-wave', 'audio/ogg',].freeze
|
||||
|
||||
IMAGE_STYLES = { original: '1280x1280>', small: '400x400>' }.freeze
|
||||
IMAGE_STYLES = {
|
||||
original: {
|
||||
geometry: '1280x1280>',
|
||||
file_geometry_parser: FastGeometryParser,
|
||||
},
|
||||
|
||||
small: {
|
||||
geometry: '400x400>',
|
||||
file_geometry_parser: FastGeometryParser,
|
||||
},
|
||||
}.freeze
|
||||
|
||||
AUDIO_STYLES = {
|
||||
original: {
|
||||
format: 'mp4',
|
||||
@@ -50,6 +61,7 @@ class MediaAttachment < ApplicationRecord
|
||||
},
|
||||
},
|
||||
}.freeze
|
||||
|
||||
VIDEO_STYLES = {
|
||||
small: {
|
||||
convert_options: {
|
||||
@@ -97,6 +109,24 @@ class MediaAttachment < ApplicationRecord
|
||||
shortcode
|
||||
end
|
||||
|
||||
def focus=(point)
|
||||
return if point.blank?
|
||||
|
||||
x, y = (point.is_a?(Enumerable) ? point : point.split(',')).map(&:to_f)
|
||||
|
||||
meta = file.instance_read(:meta) || {}
|
||||
meta['focus'] = { 'x' => x, 'y' => y }
|
||||
|
||||
file.instance_write(:meta, meta)
|
||||
end
|
||||
|
||||
def focus
|
||||
x = file.meta['focus']['x']
|
||||
y = file.meta['focus']['y']
|
||||
|
||||
"#{x},#{y}"
|
||||
end
|
||||
|
||||
before_create :prepare_description, unless: :local?
|
||||
before_create :set_shortcode
|
||||
before_post_process :set_type_and_extension
|
||||
@@ -178,7 +208,7 @@ class MediaAttachment < ApplicationRecord
|
||||
end
|
||||
|
||||
def populate_meta
|
||||
meta = {}
|
||||
meta = file.instance_read(:meta) || {}
|
||||
|
||||
file.queued_for_write.each do |style, file|
|
||||
meta[style] = style == :small || image? ? image_geometry(file) : video_metadata(file)
|
||||
@@ -188,16 +218,16 @@ class MediaAttachment < ApplicationRecord
|
||||
end
|
||||
|
||||
def image_geometry(file)
|
||||
geo = Paperclip::Geometry.from_file file
|
||||
width, height = FastImage.size(file.path)
|
||||
|
||||
return {} if width.nil?
|
||||
|
||||
{
|
||||
width: geo.width.to_i,
|
||||
height: geo.height.to_i,
|
||||
size: "#{geo.width.to_i}x#{geo.height.to_i}",
|
||||
aspect: geo.width.to_f / geo.height.to_f,
|
||||
width: width,
|
||||
height: height,
|
||||
size: "#{width}x#{height}",
|
||||
aspect: width.to_f / height.to_f,
|
||||
}
|
||||
rescue Paperclip::Errors::NotIdentifiedByImageMagickError
|
||||
{}
|
||||
end
|
||||
|
||||
def video_metadata(file)
|
||||
|
||||
@@ -33,7 +33,7 @@ class PreviewCard < ApplicationRecord
|
||||
|
||||
has_and_belongs_to_many :statuses
|
||||
|
||||
has_attached_file :image, styles: { original: '400x400>' }, convert_options: { all: '-quality 80 -strip' }
|
||||
has_attached_file :image, styles: { original: { geometry: '400x400>', file_geometry_parser: FastGeometryParser } }, convert_options: { all: '-quality 80 -strip' }
|
||||
|
||||
include Attachmentable
|
||||
include Remotable
|
||||
@@ -58,10 +58,11 @@ class PreviewCard < ApplicationRecord
|
||||
|
||||
return if file.nil?
|
||||
|
||||
geo = Paperclip::Geometry.from_file(file)
|
||||
self.width = geo.width.to_i
|
||||
self.height = geo.height.to_i
|
||||
rescue Paperclip::Errors::NotIdentifiedByImageMagickError
|
||||
nil
|
||||
width, height = FastImage.size(file.path)
|
||||
|
||||
return nil if width.nil?
|
||||
|
||||
self.width = width
|
||||
self.height = height
|
||||
end
|
||||
end
|
||||
|
||||
@@ -34,8 +34,8 @@ class SiteUpload < ApplicationRecord
|
||||
|
||||
return if tempfile.nil?
|
||||
|
||||
geometry = Paperclip::Geometry.from_file(tempfile)
|
||||
self.meta = { width: geometry.width.to_i, height: geometry.height.to_i }
|
||||
width, height = FastImage.size(tempfile.path)
|
||||
self.meta = { width: width, height: height }
|
||||
end
|
||||
|
||||
def clear_cache
|
||||
|
||||
@@ -79,7 +79,7 @@ class Status < ApplicationRecord
|
||||
|
||||
scope :not_local_only, -> { where(local_only: [false, nil]) }
|
||||
|
||||
cache_associated :account, :application, :media_attachments, :tags, :stream_entry, mentions: :account, reblog: [:account, :application, :stream_entry, :tags, :media_attachments, mentions: :account], thread: :account
|
||||
cache_associated :account, :application, :media_attachments, :conversation, :tags, :stream_entry, mentions: :account, reblog: [:account, :application, :stream_entry, :tags, :media_attachments, :conversation, mentions: :account], thread: :account
|
||||
|
||||
delegate :domain, to: :account, prefix: true
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ class User < ApplicationRecord
|
||||
accepts_nested_attributes_for :account
|
||||
|
||||
has_many :applications, class_name: 'Doorkeeper::Application', as: :owner
|
||||
has_many :backups, inverse_of: :user
|
||||
|
||||
validates :locale, inclusion: I18n.available_locales.map(&:to_s), if: :locale?
|
||||
validates_with BlacklistedEmailValidator, if: :email_changed?
|
||||
|
||||
Reference in New Issue
Block a user