Module: Postnhost::InlineImageUploadable

Extended by:
ActiveSupport::Concern
Included in:
Article::ImageUploadable, Page::ImageUploadable
Defined in:
app/models/concerns/postnhost/inline_image_uploadable.rb

Constant Summary collapse

IMAGE_MAX_SIZE =
20.megabytes
SUPPORTED_CONTENT_TYPES =
%w[image/jpeg image/png image/gif image/webp image/heic].freeze

Instance Method Summary collapse

Instance Method Details

#upload_inline_image(file) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/concerns/postnhost/inline_image_uploadable.rb', line 7

def upload_inline_image(file)
  return { success: false, error: "Invalid file type" } unless valid_image_file_type?(file)
  return { success: false, error: "File too large" } if image_file_too_large?(file)

  uploader = inline_image_uploader_class.new(self, :inline_image)
  uploader.store!(file)

  {
    success: true,
    url: uploader.url,
    filename: uploader.identifier
  }
rescue CarrierWave::ProcessingError, CarrierWave::IntegrityError => e
  Rails.logger.error("CarrierWave inline image error: #{e.message}")
  { success: false, error: "Invalid image file" }
rescue StandardError => e
  Rails.logger.error("Inline image processing error: #{e.message}")
  { success: false, error: "Error processing image" }
end