Files
docuseal/lib/docuseal.rb
T

127 lines
3.3 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
module Docuseal
2024-02-18 10:04:56 +02:00
URL_CACHE = ActiveSupport::Cache::MemoryStore.new
2024-10-31 14:25:37 +02:00
PRODUCT_URL = 'https://www.docuseal.com'
2024-11-22 10:15:51 +02:00
PRODUCT_EMAIL_URL = ENV.fetch('PRODUCT_EMAIL_URL', PRODUCT_URL)
2023-07-01 13:43:46 +03:00
NEWSLETTER_URL = "#{PRODUCT_URL}/newsletters".freeze
2023-10-21 15:33:10 +03:00
ENQUIRIES_URL = "#{PRODUCT_URL}/enquiries".freeze
2023-06-26 00:46:01 +03:00
PRODUCT_NAME = 'DocuSeal'
2024-08-24 14:57:40 +03:00
DEFAULT_APP_URL = ENV.fetch('APP_URL', 'http://localhost:3000')
2023-07-04 23:05:22 +03:00
GITHUB_URL = 'https://github.com/docusealco/docuseal'
2023-07-10 00:13:49 +03:00
DISCORD_URL = 'https://discord.gg/qygYCDGck9'
2023-07-04 23:05:22 +03:00
TWITTER_URL = 'https://twitter.com/docusealco'
2023-07-04 23:21:49 +03:00
TWITTER_HANDLE = '@docusealco'
2025-04-15 21:40:22 +03:00
CHATGPT_URL = "#{PRODUCT_URL}/chat".freeze
2024-10-16 12:16:20 +03:00
SUPPORT_EMAIL = 'support@docuseal.com'
2023-08-29 20:47:56 +03:00
HOST = ENV.fetch('HOST', 'localhost')
2024-09-26 10:58:32 +03:00
AATL_CERT_NAME = 'docuseal_aatl'
2023-08-05 11:02:00 +03:00
CONSOLE_URL = if Rails.env.development?
'http://console.localhost.io:3001'
2023-08-30 14:39:14 +03:00
elsif ENV['MULTITENANT'] == 'true'
2023-08-29 20:47:56 +03:00
"https://console.#{HOST}"
2023-08-30 14:39:14 +03:00
else
2024-10-26 09:54:41 +03:00
'https://console.docuseal.com'
2023-08-05 11:02:00 +03:00
end
2024-01-31 02:52:36 +02:00
CLOUD_URL = if Rails.env.development?
'http://localhost:3000'
else
2024-10-26 09:54:41 +03:00
'https://docuseal.com'
2024-01-31 02:52:36 +02:00
end
2023-08-25 23:44:14 +03:00
CDN_URL = if Rails.env.development?
'http://localhost:3000'
2023-08-30 14:39:14 +03:00
elsif ENV['MULTITENANT'] == 'true'
2023-08-29 20:47:56 +03:00
"https://cdn.#{HOST}"
2023-08-30 14:39:14 +03:00
else
2024-10-21 12:33:36 +03:00
'https://cdn.docuseal.com'
2023-08-25 23:44:14 +03:00
end
2023-06-30 20:31:17 +03:00
CERTS = JSON.parse(ENV.fetch('CERTS', '{}'))
2023-12-02 18:14:33 +02:00
TIMESERVER_URL = ENV.fetch('TIMESERVER_URL', nil)
2024-01-06 22:58:26 +02:00
VERSION_FILE_PATH = Rails.root.join('.version')
2026-01-13 12:17:03 +02:00
VERSION_FILE2_PATH = Rails.public_path.join('version')
2023-06-30 20:31:17 +03:00
DEFAULT_URL_OPTIONS = {
2023-08-30 14:39:14 +03:00
host: HOST,
2023-10-29 19:10:41 +02:00
protocol: ENV['FORCE_SSL'].present? ? 'https' : 'http'
2023-06-30 20:31:17 +03:00
}.freeze
module_function
2024-01-06 22:58:26 +02:00
def version
2026-01-13 12:17:03 +02:00
@version ||=
if VERSION_FILE_PATH.exist?
VERSION_FILE_PATH.read.strip
elsif VERSION_FILE2_PATH.exist?
VERSION_FILE2_PATH.each_line.first.to_s.strip
end
2024-01-06 22:58:26 +02:00
end
2023-06-26 00:46:01 +03:00
def multitenant?
2023-06-30 20:31:17 +03:00
ENV['MULTITENANT'] == 'true'
2023-06-26 00:46:01 +03:00
end
2025-05-02 19:11:29 +03:00
def advanced_formats?
multitenant?
end
2023-07-05 00:22:05 +03:00
def demo?
ENV['DEMO'] == 'true'
end
def active_storage_public?
ENV['ACTIVE_STORAGE_PUBLIC'] == 'true'
end
2024-05-01 23:40:09 +03:00
def default_pkcs
2024-12-17 23:25:04 +02:00
return if Docuseal::CERTS['enabled'] == false
2024-05-01 23:40:09 +03:00
@default_pkcs ||= GenerateCertificate.load_pkcs(Docuseal::CERTS)
end
2025-06-21 22:52:10 +03:00
def fulltext_search?
return @fulltext_search unless @fulltext_search.nil?
@fulltext_search =
if SearchEntry.table_exists?
2025-10-04 18:33:37 +03:00
Docuseal.multitenant? || AccountConfig.exists?(key: :fulltext_search, value: true)
2025-06-21 22:52:10 +03:00
else
false
end
2025-06-05 13:16:55 +03:00
end
2025-02-01 21:55:47 +02:00
def enable_pwa?
true
end
2025-07-10 12:13:27 +03:00
def pdf_format
@pdf_format ||= ENV['PDF_FORMAT'].to_s.downcase
end
2024-05-01 23:40:09 +03:00
def trusted_certs
@trusted_certs ||=
2024-05-02 13:39:47 +03:00
ENV['TRUSTED_CERTS'].to_s.gsub('\\n', "\n").split("\n\n").map do |base64|
2024-05-01 23:40:09 +03:00
OpenSSL::X509::Certificate.new(base64)
end
end
def default_url_options
2023-06-30 20:31:17 +03:00
return DEFAULT_URL_OPTIONS if multitenant?
@default_url_options ||= begin
2024-08-24 14:57:40 +03:00
value = EncryptedConfig.find_by(key: EncryptedConfig::APP_URL_KEY)&.value if ENV['APP_URL'].blank?
value ||= DEFAULT_APP_URL
url = Addressable::URI.parse(value)
{ host: url.host, port: url.port, protocol: url.scheme }
end
end
2023-10-11 21:05:42 +03:00
def product_name
PRODUCT_NAME
end
def refresh_default_url_options!
@default_url_options = nil
end
end