summaryrefslogtreecommitdiff
path: root/app/models/blob_viewer/base.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/blob_viewer/base.rb')
-rw-r--r--app/models/blob_viewer/base.rb38
1 files changed, 11 insertions, 27 deletions
diff --git a/app/models/blob_viewer/base.rb b/app/models/blob_viewer/base.rb
index 7164e4ece78..0f1430bfd98 100644
--- a/app/models/blob_viewer/base.rb
+++ b/app/models/blob_viewer/base.rb
@@ -2,11 +2,11 @@ module BlobViewer
class Base
PARTIAL_PATH_PREFIX = 'projects/blob/viewers'.freeze
- class_attribute :partial_name, :loading_partial_name, :type, :extensions, :file_types, :client_side, :binary, :switcher_icon, :switcher_title, :max_size, :absolute_max_size
+ class_attribute :partial_name, :loading_partial_name, :type, :extensions, :file_types, :load_async, :binary, :switcher_icon, :switcher_title, :max_size, :absolute_max_size
self.loading_partial_name = 'loading'
- delegate :partial_path, :loading_partial_path, :rich?, :simple?, :client_side?, :server_side?, :text?, :binary?, to: :class
+ delegate :partial_path, :loading_partial_path, :rich?, :simple?, :text?, :binary?, to: :class
attr_reader :blob
attr_accessor :override_max_size
@@ -35,12 +35,8 @@ module BlobViewer
type == :auxiliary
end
- def self.client_side?
- client_side
- end
-
- def self.server_side?
- !client_side?
+ def self.load_async?
+ load_async
end
def self.binary?
@@ -59,6 +55,10 @@ module BlobViewer
false
end
+ def load_async?
+ self.class.load_async? && render_error.nil?
+ end
+
def too_large?
max_size && blob.raw_size > max_size
end
@@ -83,29 +83,13 @@ module BlobViewer
# binary from `blob_raw_url` and does its own format validation and error
# rendering, especially for potentially large binary formats.
def render_error
- return @render_error if defined?(@render_error)
-
- @render_error =
- if server_side_but_stored_externally?
- # Files that are not stored in the repository, like LFS files and
- # build artifacts, can only be rendered using a client-side viewer,
- # since we do not want to read large amounts of data into memory on the
- # server side. Client-side viewers use JS and can fetch the file from
- # `blob_raw_url` using AJAX.
- :server_side_but_stored_externally
- elsif override_max_size ? absolutely_too_large? : too_large?
- :too_large
- end
+ if override_max_size ? absolutely_too_large? : too_large?
+ :too_large
+ end
end
def prepare!
# To be overridden by subclasses
end
-
- private
-
- def server_side_but_stored_externally?
- server_side? && blob.stored_externally?
- end
end
end