2023-05-21 17:59:36 +03:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
ActiveSupport.on_load(:active_storage_attachment) do
|
|
|
|
|
attribute :uuid, :string, default: -> { SecureRandom.uuid }
|
|
|
|
|
|
|
|
|
|
has_many_attached :preview_images
|
2024-01-30 17:53:25 +02:00
|
|
|
|
|
|
|
|
def preview_image_url
|
|
|
|
|
preview_images.joins(:blob).find_by(blob: { filename: '0.jpg' })&.url
|
|
|
|
|
end
|
2023-05-21 17:59:36 +03:00
|
|
|
end
|
|
|
|
|
|
2023-06-24 22:50:12 +03:00
|
|
|
ActiveStorage::LogSubscriber.detach_from(:active_storage) if Rails.env.production?
|
|
|
|
|
|
2023-05-21 17:59:36 +03:00
|
|
|
Rails.configuration.to_prepare do
|
|
|
|
|
ActiveStorage::DiskController.after_action do
|
|
|
|
|
response.set_header('Cache-Control', 'public, max-age=31536000') if action_name == 'show'
|
|
|
|
|
end
|
|
|
|
|
|
2023-08-12 12:34:02 +03:00
|
|
|
ActiveStorage::Blobs::ProxyController.before_action do
|
|
|
|
|
response.set_header('Access-Control-Allow-Origin', '*')
|
|
|
|
|
response.set_header('Access-Control-Allow-Methods', 'GET')
|
|
|
|
|
response.set_header('Access-Control-Allow-Headers', '*')
|
|
|
|
|
response.set_header('Access-Control-Max-Age', '1728000')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
ActiveStorage::Blobs::RedirectController.before_action do
|
|
|
|
|
response.set_header('Access-Control-Allow-Origin', '*')
|
|
|
|
|
response.set_header('Access-Control-Allow-Methods', 'GET')
|
|
|
|
|
response.set_header('Access-Control-Allow-Headers', '*')
|
|
|
|
|
response.set_header('Access-Control-Max-Age', '1728000')
|
|
|
|
|
end
|
|
|
|
|
|
2023-06-24 12:27:34 +03:00
|
|
|
ActiveStorage::DirectUploadsController.before_action do
|
|
|
|
|
next if current_user
|
2023-07-05 20:40:49 +03:00
|
|
|
next if Submitter.find_signed(cookies[:submitter_sid])
|
2023-06-24 12:27:34 +03:00
|
|
|
|
|
|
|
|
head :forbidden
|
|
|
|
|
end
|
|
|
|
|
|
2023-05-21 17:59:36 +03:00
|
|
|
LoadActiveStorageConfigs.call
|
2023-06-09 01:43:43 +03:00
|
|
|
rescue StandardError => e
|
2023-06-13 00:29:07 +03:00
|
|
|
Rails.logger.error(e)
|
2023-06-09 01:43:43 +03:00
|
|
|
|
2023-05-21 17:59:36 +03:00
|
|
|
nil
|
|
|
|
|
end
|