2018-08-03 03:15:25 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-02 18:42:37 -04:00
|
|
|
module Ci
|
|
|
|
class ArtifactBlob
|
|
|
|
include BlobLike
|
|
|
|
|
2017-10-20 18:38:15 -04:00
|
|
|
EXTENSIONS_SERVED_BY_PAGES = %w[.html .htm .txt .json].freeze
|
2017-10-03 06:34:24 -04:00
|
|
|
|
2017-05-02 18:42:37 -04:00
|
|
|
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
|
2017-10-03 06:34:24 -04:00
|
|
|
alias_method :external_size, :size
|
2017-05-02 18:42:37 -04:00
|
|
|
|
|
|
|
def data
|
|
|
|
"Build artifact #{path}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def mode
|
|
|
|
entry.metadata[:mode]
|
|
|
|
end
|
|
|
|
|
|
|
|
def external_storage
|
|
|
|
:build_artifact
|
|
|
|
end
|
|
|
|
|
2017-10-03 06:34:24 -04:00
|
|
|
def external_url(project, job)
|
2017-10-05 06:41:22 -04:00
|
|
|
return unless external_link?(job)
|
2017-10-03 06:34:24 -04:00
|
|
|
|
2018-03-29 05:24:08 -04:00
|
|
|
url_project_path = project.full_path.partition('/').last
|
2017-10-03 06:34:24 -04:00
|
|
|
|
2017-10-20 18:38:15 -04:00
|
|
|
artifact_path = [
|
2018-03-29 05:24:08 -04:00
|
|
|
'-', url_project_path, '-',
|
2017-10-20 18:38:15 -04:00
|
|
|
'jobs', job.id,
|
|
|
|
'artifacts', path
|
|
|
|
].join('/')
|
|
|
|
|
2018-03-29 05:24:08 -04:00
|
|
|
"#{project.pages_group_url}/#{artifact_path}"
|
2017-10-03 06:34:24 -04:00
|
|
|
end
|
|
|
|
|
2017-10-05 06:41:22 -04:00
|
|
|
def external_link?(job)
|
2017-10-03 06:34:24 -04:00
|
|
|
pages_config.enabled &&
|
|
|
|
pages_config.artifacts_server &&
|
2017-10-20 18:38:15 -04:00
|
|
|
EXTENSIONS_SERVED_BY_PAGES.include?(File.extname(name)) &&
|
2017-10-05 06:41:22 -04:00
|
|
|
job.project.public?
|
2017-10-03 06:34:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def pages_config
|
|
|
|
Gitlab.config.pages
|
|
|
|
end
|
2017-05-02 18:42:37 -04:00
|
|
|
end
|
|
|
|
end
|