debian-mirror-gitlab/app/models/pages/lookup_path.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
1.8 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
module Pages
class LookupPath
2021-02-22 17:27:13 +05:30
include Gitlab::Utils::StrongMemoize
2021-03-11 19:13:27 +05:30
LegacyStorageDisabledError = Class.new(::StandardError)
2019-12-21 20:55:43 +05:30
def initialize(project, trim_prefix: nil, domain: nil)
2019-12-04 20:38:33 +05:30
@project = project
@domain = domain
2019-12-21 20:55:43 +05:30
@trim_prefix = trim_prefix || project.full_path
2019-12-04 20:38:33 +05:30
end
def project_id
project.id
end
def access_control
project.private_pages?
end
2023-03-04 22:38:38 +05:30
strong_memoize_attr :access_control
2019-12-04 20:38:33 +05:30
def https_only
domain_https = domain ? domain.https? : true
project.pages_https_only? && domain_https
end
2023-03-04 22:38:38 +05:30
strong_memoize_attr :https_only
2019-12-04 20:38:33 +05:30
def source
2021-09-04 01:27:46 +05:30
return unless deployment&.file
global_id = ::Gitlab::GlobalId.build(deployment, id: deployment.id).to_s
{
type: 'zip',
2022-11-25 23:54:43 +05:30
path: deployment.file.url_or_file_path(
expire_at: ::Gitlab::Pages::CacheControl::DEPLOYMENT_EXPIRATION.from_now
),
2021-09-04 01:27:46 +05:30
global_id: global_id,
sha256: deployment.file_sha256,
file_size: deployment.size,
file_count: deployment.file_count
}
2019-12-04 20:38:33 +05:30
end
2023-03-04 22:38:38 +05:30
strong_memoize_attr :source
2019-12-04 20:38:33 +05:30
def prefix
2023-03-17 16:20:25 +05:30
if project.pages_namespace_url == project.pages_url
2019-12-21 20:55:43 +05:30
'/'
else
2023-05-27 22:25:52 +05:30
"#{project.full_path.delete_prefix(trim_prefix)}/"
2019-12-21 20:55:43 +05:30
end
2019-12-04 20:38:33 +05:30
end
2023-03-04 22:38:38 +05:30
strong_memoize_attr :prefix
2019-12-04 20:38:33 +05:30
2023-06-20 00:43:36 +05:30
def unique_host
2023-05-27 22:25:52 +05:30
return unless project.project_setting.pages_unique_domain_enabled?
2023-06-20 00:43:36 +05:30
project.pages_unique_host
2023-05-27 22:25:52 +05:30
end
2023-06-20 00:43:36 +05:30
strong_memoize_attr :unique_host
def root_directory
return unless deployment
deployment.root_directory
end
strong_memoize_attr :root_directory
2023-05-27 22:25:52 +05:30
2019-12-04 20:38:33 +05:30
private
2019-12-21 20:55:43 +05:30
attr_reader :project, :trim_prefix, :domain
2020-11-24 15:15:51 +05:30
2021-01-29 00:20:46 +05:30
def deployment
2023-05-27 22:25:52 +05:30
project.pages_metadatum.pages_deployment
2020-11-24 15:15:51 +05:30
end
2023-05-27 22:25:52 +05:30
strong_memoize_attr :deployment
2019-12-04 20:38:33 +05:30
end
end