Welcome to mirror list, hosted at ThFree Co, Russian Federation.

lookup_path.rb « pages « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9855731778f8359dec366a54378c547f558a9fa1 (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
# frozen_string_literal: true

module Pages
  class LookupPath
    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

    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
      zip_source || file_source
    end

    def prefix
      if project.pages_group_root?
        '/'
      else
        project.full_path.delete_prefix(trim_prefix) + '/'
      end
    end

    private

    attr_reader :project, :trim_prefix, :domain

    def artifacts_archive
      return unless Feature.enabled?(:pages_serve_from_artifacts_archive, project)

      project.pages_metadatum.artifacts_archive
    end

    def deployment
      return unless Feature.enabled?(:pages_serve_from_deployments, project)

      project.pages_metadatum.pages_deployment
    end

    def zip_source
      source = deployment || artifacts_archive

      return unless source&.file

      return if source.file.file_storage? && !Feature.enabled?(:pages_serve_with_zip_file_protocol, project)

      # artifacts archive doesn't support this
      file_count = source.file_count if source.respond_to?(:file_count)

      global_id = ::Gitlab::GlobalId.build(source, id: source.id).to_s

      {
        type: 'zip',
        path: source.file.url_or_file_path(expire_at: 1.day.from_now),
        global_id: global_id,
        sha256: source.file_sha256,
        file_size: source.size,
        file_count: file_count
      }
    end

    def file_source
      {
        type: 'file',
        path: File.join(project.full_path, 'public/')
      }
    end
  end
end