summaryrefslogtreecommitdiff
path: root/app/models/ci/artifact_blob.rb
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <git@zjvandeweg.nl>2017-10-03 12:34:24 +0200
committerZeger-Jan van de Weg <git@zjvandeweg.nl>2017-10-03 12:34:24 +0200
commit8cbfe3aea64a11f8de0e28e35fc1fc298128158e (patch)
treea12867e59b7ae7584f3a67a406f832bd7cab7ee8 /app/models/ci/artifact_blob.rb
parentca0e39048f0e92bd615c45bfe555800910396cfd (diff)
downloadgitlab-ce-8cbfe3aea64a11f8de0e28e35fc1fc298128158e.tar.gz
Redirect to pages daemon
Diffstat (limited to 'app/models/ci/artifact_blob.rb')
-rw-r--r--app/models/ci/artifact_blob.rb25
1 files changed, 24 insertions, 1 deletions
diff --git a/app/models/ci/artifact_blob.rb b/app/models/ci/artifact_blob.rb
index b35febc9ac5..e03d11284c0 100644
--- a/app/models/ci/artifact_blob.rb
+++ b/app/models/ci/artifact_blob.rb
@@ -2,6 +2,8 @@ module Ci
class ArtifactBlob
include BlobLike
+ EXTENTIONS_SERVED_BY_PAGES = %w[.html .htm .txt].freeze
+
attr_reader :entry
def initialize(entry)
@@ -17,6 +19,7 @@ module Ci
def size
entry.metadata[:size]
end
+ alias_method :external_size, :size
def data
"Build artifact #{path}"
@@ -30,6 +33,26 @@ module Ci
:build_artifact
end
- alias_method :external_size, :size
+ 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
end
end