Source code for the custom Mastodon (Glitchsoc) instance on berserker.town.
https://berserker.town/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
787 B
22 lines
787 B
# frozen_string_literal: true
|
|
|
|
module Paperclip
|
|
module MediaTypeSpoofDetectorExtensions
|
|
def calculated_content_type
|
|
return @calculated_content_type if defined?(@calculated_content_type)
|
|
|
|
@calculated_content_type = type_from_file_command.chomp
|
|
|
|
# The `file` command fails to recognize some MP3 files as such
|
|
@calculated_content_type = type_from_marcel if @calculated_content_type == 'application/octet-stream' && type_from_marcel == 'audio/mpeg'
|
|
@calculated_content_type
|
|
end
|
|
|
|
def type_from_marcel
|
|
@type_from_marcel ||= Marcel::MimeType.for Pathname.new(@file.path),
|
|
name: @file.path
|
|
end
|
|
end
|
|
end
|
|
|
|
Paperclip::MediaTypeSpoofDetector.prepend(Paperclip::MediaTypeSpoofDetectorExtensions)
|
|
|