Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
mohemohe committed Dec 26, 2023
2 parents 16bf558 + 9b05972 commit c886f31
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions app/models/media_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
# thumbnail_remote_url :string
#

require 'http'

class MediaAttachment < ApplicationRecord
self.inheritance_column = nil

Expand Down Expand Up @@ -321,23 +323,29 @@ def file_processors(instance)
private

def set_unknown_type
if file.blank? && !type_changed?
if ENV['DISABLE_REMOTE_MEDIA_CACHE'] == 'true'
mime = MimeMagic.by_path(File.basename(remote_url))
return self.type = :unknown if mime.nil?

self.type = begin
if VIDEO_MIME_TYPES.include?(mime)
:video
elsif AUDIO_MIME_TYPES.include?(mime)
:audio
else
:image
end
return unless file.blank? && !type_changed?

if ENV['DISABLE_REMOTE_MEDIA_CACHE'] == 'true'
mime = MimeMagic.by_path(File.basename(remote_url))
if mime.nil?
response = HTTP.head(remote_url)
content_type = response.headers['Content-Type']
return self.type = :unknown if content_type.blank?

mime = MimeMagic.by_mime(content_type)
end

self.type = begin
if VIDEO_MIME_TYPES.include?(mime)
:video
elsif AUDIO_MIME_TYPES.include?(mime)
:audio
else
:image
end
else
self.type = :unknown
end
else
self.type = :unknown
end
end

Expand Down

0 comments on commit c886f31

Please sign in to comment.