blob: e5e23c3bb84459e4c940e23913875960ed31f0f3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# frozen_string_literal: true
module Pages
class LookupPath
include Gitlab::Utils::StrongMemoize
def initialize(project, trim_prefix: nil, domain: nil)
@project = project
@domain = domain
@trim_prefix = trim_prefix || project.full_path
end
def project_id
project.id
end
strong_memoize_attr :project_id
def access_control
project.private_pages?
end
strong_memoize_attr :access_control
def https_only
domain_https = domain ? domain.https? : true
project.pages_https_only? && domain_https
end
strong_memoize_attr :https_only
def source
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: ::Gitlab::Pages::DEPLOYMENT_EXPIRATION.from_now
),
global_id: global_id,
sha256: deployment.file_sha256,
file_size: deployment.size,
file_count: deployment.file_count
}
end
strong_memoize_attr :source
def prefix
if url_builder.namespace_pages?
'/'
else
"#{project.full_path.delete_prefix(trim_prefix)}/"
end
end
strong_memoize_attr :prefix
def unique_host
# When serving custom domain we don't present the unique host to avoid
# GitLab Pages auto-redirect to the unique domain instead of keeping serving
# from the custom domain.
# https://gitlab.com/gitlab-org/gitlab/-/issues/426435
return if domain.present?
url_builder.unique_host
end
strong_memoize_attr :unique_host
def root_directory
return unless deployment
deployment.root_directory
end
strong_memoize_attr :root_directory
private
attr_reader :project, :trim_prefix, :domain
# project.active_pages_deployments is already loaded from the database,
# so selecting from the array to avoid N+1
# this will change with when serving multiple versions on
# https://gitlab.com/gitlab-org/gitlab/-/merge_requests/133261
def deployment
project
.active_pages_deployments
.to_a
.find { |deployment| deployment.path_prefix.blank? }
end
strong_memoize_attr :deployment
def url_builder
Gitlab::Pages::UrlBuilder.new(project)
end
strong_memoize_attr :url_builder
end
end
|