Module: Livechat::AttachmentPolicy

Defined in:
lib/livechat/attachment_policy.rb

Overview

The small set of uploads the engine renders in a browser instead of downloading. Active Storage owns the safe image/PDF allowlist; Livechat adds common audio formats because voice messages are a first-class feature.

Constant Summary collapse

INLINE_AUDIO_TYPES =
%w[
  audio/mpeg audio/mp4 audio/ogg audio/wav audio/webm audio/x-wav
].freeze

Class Method Summary collapse

Class Method Details

.audio?(content_type) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/livechat/attachment_policy.rb', line 23

def audio?(content_type)
  INLINE_AUDIO_TYPES.include?(content_type)
end

.image?(content_type) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/livechat/attachment_policy.rb', line 18

def image?(content_type)
  content_type.to_s.start_with?('image/') &&
    ActiveStorage.content_types_allowed_inline.include?(content_type)
end

.inline?(content_type) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/livechat/attachment_policy.rb', line 14

def inline?(content_type)
  audio?(content_type) || ActiveStorage.content_types_allowed_inline.include?(content_type)
end