1# frozen_string_literal: true
2
3module Pages
4  class DeploymentUploader < GitlabUploader
5    include ObjectStorage::Concern
6
7    storage_options Gitlab.config.pages
8
9    alias_method :upload, :model
10
11    private
12
13    def dynamic_segment
14      Gitlab::HashedPath.new('pages_deployments', model.id, root_hash: model.project_id)
15    end
16
17    # @hashed is chosen to avoid conflict with namespace name because we use the same directory for storage
18    # @ is not valid character for namespace
19    def base_dir
20      "@hashed"
21    end
22
23    # override GitlabUploader
24    # if set to true it erases the original file when uploading
25    # and we copy from the artifacts archive, so artifacts end up
26    # without the file
27    def move_to_cache
28      false
29    end
30
31    class << self
32      # we only upload this files from the rails background job
33      # so we don't need direct upload for pages deployments
34      # this method is here to ignore any user setting
35      def direct_upload_enabled?
36        false
37      end
38
39      # we don't need background uploads because we upload files
40      # to the right store right away, and we already do that in
41      # the background job
42      def background_upload_enabled?
43        false
44      end
45
46      def default_store
47        object_store_enabled? ? ObjectStorage::Store::REMOTE : ObjectStorage::Store::LOCAL
48      end
49    end
50  end
51end
52