Commit 4328bc17 authored by Douwe Maan's avatar Douwe Maan

Allow blob viewer to support multiple filetypes

parent 361b2b13
...@@ -2,7 +2,7 @@ module BlobViewer ...@@ -2,7 +2,7 @@ module BlobViewer
class Base class Base
PARTIAL_PATH_PREFIX = 'projects/blob/viewers'.freeze PARTIAL_PATH_PREFIX = 'projects/blob/viewers'.freeze
class_attribute :partial_name, :loading_partial_name, :type, :extensions, :file_type, :client_side, :binary, :switcher_icon, :switcher_title, :max_size, :absolute_max_size class_attribute :partial_name, :loading_partial_name, :type, :extensions, :file_types, :client_side, :binary, :switcher_icon, :switcher_title, :max_size, :absolute_max_size
self.loading_partial_name = 'loading' self.loading_partial_name = 'loading'
...@@ -54,17 +54,17 @@ module BlobViewer ...@@ -54,17 +54,17 @@ module BlobViewer
def self.can_render?(blob, verify_binary: true) def self.can_render?(blob, verify_binary: true)
return false if verify_binary && binary? != blob.binary? return false if verify_binary && binary? != blob.binary?
return true if extensions&.include?(blob.extension) return true if extensions&.include?(blob.extension)
return true if file_type && Gitlab::FileDetector.type_of(blob.path) == file_type return true if file_types&.include?(Gitlab::FileDetector.type_of(blob.path))
false false
end end
def too_large? def too_large?
blob.raw_size > max_size max_size && blob.raw_size > max_size
end end
def absolutely_too_large? def absolutely_too_large?
blob.raw_size > absolute_max_size absolute_max_size && blob.raw_size > absolute_max_size
end end
def can_override_max_size? def can_override_max_size?
......
...@@ -5,7 +5,7 @@ module BlobViewer ...@@ -5,7 +5,7 @@ module BlobViewer
self.partial_name = 'gitlab_ci_yml' self.partial_name = 'gitlab_ci_yml'
self.loading_partial_name = 'gitlab_ci_yml_loading' self.loading_partial_name = 'gitlab_ci_yml_loading'
self.file_type = :gitlab_ci self.file_types = %i(gitlab_ci)
self.binary = false self.binary = false
def validation_message def validation_message
......
...@@ -7,7 +7,7 @@ module BlobViewer ...@@ -7,7 +7,7 @@ module BlobViewer
include Auxiliary include Auxiliary
self.partial_name = 'license' self.partial_name = 'license'
self.file_type = :license self.file_types = %i(license)
self.binary = false self.binary = false
def license def license
......
...@@ -5,7 +5,7 @@ module BlobViewer ...@@ -5,7 +5,7 @@ module BlobViewer
self.partial_name = 'route_map' self.partial_name = 'route_map'
self.loading_partial_name = 'route_map_loading' self.loading_partial_name = 'route_map_loading'
self.file_type = :route_map self.file_types = %i(route_map)
self.binary = false self.binary = false
def validation_message def validation_message
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment