2019-09-06 01:20:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Pages
|
|
|
|
class LookupPath
|
2020-11-20 19:09:36 -05:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2021-01-21 13:09:11 -05:00
|
|
|
LegacyStorageDisabledError = Class.new(::StandardError)
|
|
|
|
|
2019-09-25 05:06:04 -04:00
|
|
|
def initialize(project, trim_prefix: nil, domain: nil)
|
2019-09-06 01:20:05 -04:00
|
|
|
@project = project
|
|
|
|
@domain = domain
|
2019-09-25 05:06:04 -04:00
|
|
|
@trim_prefix = trim_prefix || project.full_path
|
2019-09-06 01:20:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def project_id
|
|
|
|
project.id
|
|
|
|
end
|
|
|
|
|
|
|
|
def access_control
|
|
|
|
project.private_pages?
|
|
|
|
end
|
|
|
|
|
|
|
|
def https_only
|
|
|
|
domain_https = domain ? domain.https? : true
|
|
|
|
project.pages_https_only? && domain_https
|
|
|
|
end
|
|
|
|
|
|
|
|
def source
|
2021-06-08 14:10:23 -04:00
|
|
|
return unless deployment&.file
|
|
|
|
|
|
|
|
global_id = ::Gitlab::GlobalId.build(deployment, id: deployment.id).to_s
|
|
|
|
|
|
|
|
{
|
|
|
|
type: 'zip',
|
|
|
|
path: deployment.file.url_or_file_path(expire_at: 1.day.from_now),
|
|
|
|
global_id: global_id,
|
|
|
|
sha256: deployment.file_sha256,
|
|
|
|
file_size: deployment.size,
|
|
|
|
file_count: deployment.file_count
|
|
|
|
}
|
2019-09-06 01:20:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def prefix
|
2019-09-25 05:06:04 -04:00
|
|
|
if project.pages_group_root?
|
|
|
|
'/'
|
|
|
|
else
|
|
|
|
project.full_path.delete_prefix(trim_prefix) + '/'
|
|
|
|
end
|
2019-09-06 01:20:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-09-25 05:06:04 -04:00
|
|
|
attr_reader :project, :trim_prefix, :domain
|
2020-09-04 14:08:48 -04:00
|
|
|
|
2020-11-10 16:08:51 -05:00
|
|
|
def deployment
|
2020-11-20 19:09:36 -05:00
|
|
|
strong_memoize(:deployment) do
|
|
|
|
project.pages_metadatum.pages_deployment
|
|
|
|
end
|
2020-09-04 14:08:48 -04:00
|
|
|
end
|
2019-09-06 01:20:05 -04:00
|
|
|
end
|
|
|
|
end
|