|
|
|
@ -21,6 +21,8 @@ class Account < ApplicationRecord
|
|
|
|
|
validates_attachment_content_type :header, content_type: IMAGE_MIME_TYPES
|
|
|
|
|
validates_attachment_size :header, less_than: 2.megabytes
|
|
|
|
|
|
|
|
|
|
before_post_process :set_file_extensions
|
|
|
|
|
|
|
|
|
|
# Local user profile validations
|
|
|
|
|
validates :display_name, length: { maximum: 30 }, if: 'local?'
|
|
|
|
|
validates :note, length: { maximum: 160 }, if: 'local?'
|
|
|
|
@ -332,4 +334,20 @@ class Account < ApplicationRecord
|
|
|
|
|
self.public_key = keypair.public_key.to_pem
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def set_file_extensions
|
|
|
|
|
unless avatar.blank?
|
|
|
|
|
extension = Paperclip::Interpolations.content_type_extension(avatar, :original)
|
|
|
|
|
basename = Paperclip::Interpolations.basename(avatar, :original)
|
|
|
|
|
avatar.instance_write :file_name, [basename, extension].delete_if(&:empty?).join('.')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
unless header.blank?
|
|
|
|
|
extension = Paperclip::Interpolations.content_type_extension(header, :original)
|
|
|
|
|
basename = Paperclip::Interpolations.basename(header, :original)
|
|
|
|
|
header.instance_write :file_name, [basename, extension].delete_if(&:empty?).join('.')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|