chore: Add down gem for Local file downloads (#2765)
- Add down gem to handle downloading files to host machine - Remove the LocalResource class - Introduce max limit for contact avatars send via SDK
This commit is contained in:
@@ -36,7 +36,7 @@ class ChatwootHub
|
||||
info = info.merge(instance_metrics) unless ENV['DISABLE_TELEMETRY']
|
||||
response = RestClient.post(PING_URL, info.to_json, { content_type: :json, accept: :json })
|
||||
version = JSON.parse(response)['version']
|
||||
rescue *ExceptionList::REST_CLIENT_EXCEPTIONS, *ExceptionList::URI_EXCEPTIONS => e
|
||||
rescue *ExceptionList::REST_CLIENT_EXCEPTIONS => e
|
||||
Rails.logger.info "Exception: #{e.message}"
|
||||
rescue StandardError => e
|
||||
Sentry.capture_exception(e)
|
||||
@@ -47,7 +47,7 @@ class ChatwootHub
|
||||
def self.register_instance(company_name, owner_name, owner_email)
|
||||
info = { company_name: company_name, owner_name: owner_name, owner_email: owner_email, subscribed_to_mailers: true }
|
||||
RestClient.post(REGISTRATION_URL, info.merge(instance_config).to_json, { content_type: :json, accept: :json })
|
||||
rescue *ExceptionList::REST_CLIENT_EXCEPTIONS, *ExceptionList::URI_EXCEPTIONS => e
|
||||
rescue *ExceptionList::REST_CLIENT_EXCEPTIONS => e
|
||||
Rails.logger.info "Exception: #{e.message}"
|
||||
rescue StandardError => e
|
||||
Raven.capture_exception(e)
|
||||
@@ -58,7 +58,7 @@ class ChatwootHub
|
||||
|
||||
info = { event_name: event_name, event_data: event_data }
|
||||
RestClient.post(EVENTS_URL, info.merge(instance_config).to_json, { content_type: :json, accept: :json })
|
||||
rescue *ExceptionList::REST_CLIENT_EXCEPTIONS, *ExceptionList::URI_EXCEPTIONS => e
|
||||
rescue *ExceptionList::REST_CLIENT_EXCEPTIONS => e
|
||||
Rails.logger.info "Exception: #{e.message}"
|
||||
rescue StandardError => e
|
||||
Sentry.capture_exception(e)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module ExceptionList
|
||||
URI_EXCEPTIONS = [Errno::ETIMEDOUT, Errno::ECONNREFUSED, URI::InvalidURIError, Net::OpenTimeout, SocketError].freeze
|
||||
REST_CLIENT_EXCEPTIONS = [RestClient::NotFound, RestClient::GatewayTimeout, RestClient::BadRequest,
|
||||
RestClient::MethodNotAllowed, RestClient::Forbidden, RestClient::InternalServerError, RestClient::PayloadTooLarge].freeze
|
||||
RestClient::MethodNotAllowed, RestClient::Forbidden, RestClient::InternalServerError,
|
||||
RestClient::PayloadTooLarge, SocketError].freeze
|
||||
SMTP_EXCEPTIONS = [
|
||||
Net::SMTPSyntaxError
|
||||
].freeze
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
class LocalResource
|
||||
attr_reader :uri
|
||||
|
||||
def initialize(uri, file_type = nil)
|
||||
@uri = URI(uri)
|
||||
@file_type = file_type
|
||||
end
|
||||
|
||||
def file
|
||||
@file ||= Tempfile.new(tmp_filename, tmp_folder, encoding: encoding).tap do |f|
|
||||
io.rewind
|
||||
f.write(io.read)
|
||||
f.close
|
||||
end
|
||||
@file.open
|
||||
end
|
||||
|
||||
def io
|
||||
# TODO: should we use RestClient here too ?
|
||||
@io ||= uri.open(read_timeout: 5)
|
||||
end
|
||||
|
||||
def encoding
|
||||
io.rewind
|
||||
io.read.encoding
|
||||
end
|
||||
|
||||
def find_file_type
|
||||
@file_type ? @file_type.split('/').last : Pathname.new(uri.path).extname
|
||||
end
|
||||
|
||||
def tmp_filename
|
||||
[Time.now.to_i.to_s, find_file_type].join('.')
|
||||
end
|
||||
|
||||
def tmp_folder
|
||||
Rails.root.join('tmp')
|
||||
end
|
||||
|
||||
def filename
|
||||
File.basename(uri.path)
|
||||
end
|
||||
end
|
||||
@@ -6,7 +6,7 @@ class Webhooks::Trigger
|
||||
headers: { content_type: :json, accept: :json },
|
||||
timeout: 5
|
||||
)
|
||||
rescue *ExceptionList::REST_CLIENT_EXCEPTIONS, *ExceptionList::URI_EXCEPTIONS => e
|
||||
rescue *ExceptionList::REST_CLIENT_EXCEPTIONS => e
|
||||
Rails.logger.info "Exception: invalid webhook url #{url} : #{e.message}"
|
||||
rescue StandardError => e
|
||||
Sentry.capture_exception(e)
|
||||
|
||||
Reference in New Issue
Block a user