BigW Consortium Gitlab

artifact_blob.rb 1.09 KB
Newer Older
1 2 3 4
module Ci
  class ArtifactBlob
    include BlobLike

5
    EXTENTIONS_SERVED_BY_PAGES = %w[.html .htm .txt .json].freeze
6

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
    attr_reader :entry

    def initialize(entry)
      @entry = entry
    end

    delegate :name, :path, to: :entry

    def id
      Digest::SHA1.hexdigest(path)
    end

    def size
      entry.metadata[:size]
    end
22
    alias_method :external_size, :size
23 24 25 26 27 28 29 30 31 32 33 34 35

    def data
      "Build artifact #{path}"
    end

    def mode
      entry.metadata[:mode]
    end

    def external_storage
      :build_artifact
    end

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    def external_url(project, job)
      return unless external_link?

      components = project.full_path_components
      components << "-/jobs/#{job.id}/artifacts/file/#{path}"
      artifact_path = components[1..-1].join('/')

      "#{pages_config.protocol}://#{components[0]}.#{pages_config.host}/#{artifact_path}"
    end

    def external_link?
      pages_config.enabled &&
        pages_config.artifacts_server &&
        EXTENTIONS_SERVED_BY_PAGES.include?(File.extname(name))
    end

    private

    def pages_config
      Gitlab.config.pages
    end
57 58
  end
end