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
|
|
|
|
|
|
|
|
def https_only
|
|
|
|
domain_https = domain ? domain.https? : true
|
|
|
|
project.pages_https_only? && domain_https
|
|
|
|
end
|
|
|
|
|
|
|
|
def source
|
2021-03-11 19:13:27 +05:30
|
|
|
zip_source || legacy_source
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def prefix
|
2019-12-21 20:55:43 +05:30
|
|
|
if project.pages_group_root?
|
|
|
|
'/'
|
|
|
|
else
|
|
|
|
project.full_path.delete_prefix(trim_prefix) + '/'
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
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
|
2021-02-22 17:27:13 +05:30
|
|
|
strong_memoize(:deployment) do
|
|
|
|
project.pages_metadatum.pages_deployment
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def zip_source
|
2021-02-22 17:27:13 +05:30
|
|
|
return unless deployment&.file
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
global_id = ::Gitlab::GlobalId.build(deployment, id: deployment.id).to_s
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
{
|
|
|
|
type: 'zip',
|
2021-02-22 17:27:13 +05:30
|
|
|
path: deployment.file.url_or_file_path(expire_at: 1.day.from_now),
|
2021-01-29 00:20:46 +05:30
|
|
|
global_id: global_id,
|
2021-02-22 17:27:13 +05:30
|
|
|
sha256: deployment.file_sha256,
|
|
|
|
file_size: deployment.size,
|
|
|
|
file_count: deployment.file_count
|
2020-11-24 15:15:51 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
# TODO: remove support for legacy storage in 14.3 https://gitlab.com/gitlab-org/gitlab/-/issues/328712
|
|
|
|
# we support this till 14.3 to allow people to still use legacy storage if something goes very wrong
|
|
|
|
# on self-hosted installations, and we'll need some time to fix it
|
2021-03-11 19:13:27 +05:30
|
|
|
def legacy_source
|
2021-06-08 01:23:25 +05:30
|
|
|
return unless ::Settings.pages.local_store.enabled
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
{
|
|
|
|
type: 'file',
|
|
|
|
path: File.join(project.full_path, 'public/')
|
|
|
|
}
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
end
|