diff options
Diffstat (limited to 'app/models/blob_viewer')
-rw-r--r-- | app/models/blob_viewer/auxiliary.rb | 2 | ||||
-rw-r--r-- | app/models/blob_viewer/base.rb | 22 | ||||
-rw-r--r-- | app/models/blob_viewer/client_side.rb | 4 | ||||
-rw-r--r-- | app/models/blob_viewer/server_side.rb | 4 | ||||
-rw-r--r-- | app/models/blob_viewer/text.rb | 4 |
5 files changed, 22 insertions, 14 deletions
diff --git a/app/models/blob_viewer/auxiliary.rb b/app/models/blob_viewer/auxiliary.rb index db124397b27..cd6e596ed60 100644 --- a/app/models/blob_viewer/auxiliary.rb +++ b/app/models/blob_viewer/auxiliary.rb @@ -5,8 +5,8 @@ module BlobViewer included do self.loading_partial_name = 'loading_auxiliary' self.type = :auxiliary + self.overridable_max_size = 100.kilobytes self.max_size = 100.kilobytes - self.absolute_max_size = 100.kilobytes end end end diff --git a/app/models/blob_viewer/base.rb b/app/models/blob_viewer/base.rb index 0f1430bfd98..c7b8fbfc56a 100644 --- a/app/models/blob_viewer/base.rb +++ b/app/models/blob_viewer/base.rb @@ -2,7 +2,7 @@ module BlobViewer class Base PARTIAL_PATH_PREFIX = 'projects/blob/viewers'.freeze - class_attribute :partial_name, :loading_partial_name, :type, :extensions, :file_types, :load_async, :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, :overridable_max_size, :max_size self.loading_partial_name = 'loading' @@ -59,16 +59,24 @@ module BlobViewer self.class.load_async? && render_error.nil? end - def too_large? - max_size && blob.raw_size > max_size + def exceeds_overridable_max_size? + overridable_max_size && blob.raw_size > overridable_max_size end - def absolutely_too_large? - absolute_max_size && blob.raw_size > absolute_max_size + def exceeds_max_size? + max_size && blob.raw_size > max_size end def can_override_max_size? - too_large? && !absolutely_too_large? + exceeds_overridable_max_size? && !exceeds_max_size? + end + + def too_large? + if override_max_size + exceeds_max_size? + else + exceeds_overridable_max_size? + end end # This method is used on the server side to check whether we can attempt to @@ -83,7 +91,7 @@ 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 - if override_max_size ? absolutely_too_large? : too_large? + if too_large? :too_large end end diff --git a/app/models/blob_viewer/client_side.rb b/app/models/blob_viewer/client_side.rb index 27e48528dae..cc68236f92b 100644 --- a/app/models/blob_viewer/client_side.rb +++ b/app/models/blob_viewer/client_side.rb @@ -4,8 +4,8 @@ module BlobViewer included do self.load_async = false - self.max_size = 10.megabytes - self.absolute_max_size = 50.megabytes + self.overridable_max_size = 10.megabytes + self.max_size = 50.megabytes end end end diff --git a/app/models/blob_viewer/server_side.rb b/app/models/blob_viewer/server_side.rb index ed8c1373f53..87884dcd6bf 100644 --- a/app/models/blob_viewer/server_side.rb +++ b/app/models/blob_viewer/server_side.rb @@ -4,8 +4,8 @@ module BlobViewer included do self.load_async = true - self.max_size = 2.megabytes - self.absolute_max_size = 5.megabytes + self.overridable_max_size = 2.megabytes + self.max_size = 5.megabytes end def prepare! diff --git a/app/models/blob_viewer/text.rb b/app/models/blob_viewer/text.rb index e27b2c2b493..eddca50b4d4 100644 --- a/app/models/blob_viewer/text.rb +++ b/app/models/blob_viewer/text.rb @@ -5,7 +5,7 @@ module BlobViewer self.partial_name = 'text' self.binary = false - self.max_size = 1.megabyte - self.absolute_max_size = 10.megabytes + self.overridable_max_size = 1.megabyte + self.max_size = 10.megabytes end end |