mirror of
https://github.com/mastodon/mastodon.git
synced 2025-02-12 01:45:08 +00:00
![Eugen Rochko](/assets/img/avatar_default.png)
Some checks failed
Check i18n / check-i18n (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (ruby) (push) Has been cancelled
Crowdin / Upload translations / upload-translations (push) Has been cancelled
Check formatting / lint (push) Has been cancelled
CSS Linting / lint (push) Has been cancelled
Haml Linting / lint (push) Has been cancelled
JavaScript Linting / lint (push) Has been cancelled
Ruby Linting / lint (push) Has been cancelled
JavaScript Testing / test (push) Has been cancelled
Historical data migration test / test (14-alpine) (push) Has been cancelled
Historical data migration test / test (15-alpine) (push) Has been cancelled
Historical data migration test / test (16-alpine) (push) Has been cancelled
Historical data migration test / test (17-alpine) (push) Has been cancelled
Ruby Testing / build (production) (push) Has been cancelled
Ruby Testing / build (test) (push) Has been cancelled
Build nightly container image / compute-suffix (push) Has been cancelled
PR Needs Rebase / label-rebase-needed (push) Has been cancelled
Ruby Testing / test (.ruby-version) (push) Has been cancelled
Ruby Testing / test (3.2) (push) Has been cancelled
Ruby Testing / Libvips tests (.ruby-version) (push) Has been cancelled
Ruby Testing / Libvips tests (3.2) (push) Has been cancelled
Ruby Testing / End to End testing (.ruby-version) (push) Has been cancelled
Ruby Testing / End to End testing (3.2) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Has been cancelled
Build nightly container image / build-image (push) Has been cancelled
Build nightly container image / build-image-streaming (push) Has been cancelled
Bundler Audit / security (push) Has been cancelled
37 lines
1.4 KiB
Ruby
37 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Account::Avatar
|
|
extend ActiveSupport::Concern
|
|
|
|
AVATAR_IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'].freeze
|
|
AVATAR_LIMIT = Rails.configuration.x.use_vips ? 8.megabytes : 2.megabytes
|
|
AVATAR_DIMENSIONS = [400, 400].freeze
|
|
AVATAR_GEOMETRY = [AVATAR_DIMENSIONS.first, AVATAR_DIMENSIONS.last].join('x')
|
|
|
|
class_methods do
|
|
def avatar_styles(file)
|
|
styles = { original: { geometry: "#{AVATAR_GEOMETRY}#", file_geometry_parser: FastGeometryParser } }
|
|
styles[:static] = { geometry: "#{AVATAR_GEOMETRY}#", format: 'png', convert_options: '-coalesce', file_geometry_parser: FastGeometryParser } if file.content_type == 'image/gif'
|
|
styles
|
|
end
|
|
|
|
private :avatar_styles
|
|
end
|
|
|
|
included do
|
|
# Avatar upload
|
|
has_attached_file :avatar, styles: ->(f) { avatar_styles(f) }, convert_options: { all: '+profile "!icc,*" +set date:modify +set date:create +set date:timestamp' }, processors: [:lazy_thumbnail]
|
|
validates_attachment_content_type :avatar, content_type: AVATAR_IMAGE_MIME_TYPES
|
|
validates_attachment_size :avatar, less_than: AVATAR_LIMIT
|
|
remotable_attachment :avatar, AVATAR_LIMIT, suppress_errors: false
|
|
end
|
|
|
|
def avatar_original_url
|
|
avatar.url(:original)
|
|
end
|
|
|
|
def avatar_static_url
|
|
avatar_content_type == 'image/gif' ? avatar.url(:static) : avatar_original_url
|
|
end
|
|
end
|