summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2017-06-07 16:07:57 -0500
committerDouwe Maan <douwe@selenight.nl>2017-06-08 12:49:03 -0500
commit370bc86fb007c1683495bdf4082bf5442b517895 (patch)
tree3b435d88b5d18b96ca0ffb26f8a1618fba342bcc /app/models
parent7bd5b8c1c709163547ec865484b341211158ebf1 (diff)
downloadgitlab-ce-370bc86fb007c1683495bdf4082bf5442b517895.tar.gz
Detect if file that appears to be text in the first 1024 bytes is actually binary afer loading all datadm-blob-binaryness-change
Diffstat (limited to 'app/models')
-rw-r--r--app/models/blob.rb7
-rw-r--r--app/models/blob_viewer/base.rb14
2 files changed, 12 insertions, 9 deletions
diff --git a/app/models/blob.rb b/app/models/blob.rb
index 3869e79ba75..954d4e4d779 100644
--- a/app/models/blob.rb
+++ b/app/models/blob.rb
@@ -191,9 +191,12 @@ class Blob < SimpleDelegator
rendered_as_text? && rich_viewer
end
+ def expanded?
+ !!@expanded
+ end
+
def expand!
- simple_viewer&.expanded = true
- rich_viewer&.expanded = true
+ @expanded = true
end
private
diff --git a/app/models/blob_viewer/base.rb b/app/models/blob_viewer/base.rb
index d2aa33d994e..35965d01692 100644
--- a/app/models/blob_viewer/base.rb
+++ b/app/models/blob_viewer/base.rb
@@ -6,15 +6,15 @@ module BlobViewer
self.loading_partial_name = 'loading'
- delegate :partial_path, :loading_partial_path, :rich?, :simple?, :text?, :binary?, to: :class
+ delegate :partial_path, :loading_partial_path, :rich?, :simple?, :load_async?, :text?, :binary?, to: :class
attr_reader :blob
- attr_accessor :expanded
delegate :project, to: :blob
def initialize(blob)
@blob = blob
+ @initially_binary = blob.binary?
end
def self.partial_path
@@ -57,14 +57,10 @@ module BlobViewer
false
end
- def load_async?
- self.class.load_async? && render_error.nil?
- end
-
def collapsed?
return @collapsed if defined?(@collapsed)
- @collapsed = !expanded && collapse_limit && blob.raw_size > collapse_limit
+ @collapsed = !blob.expanded? && collapse_limit && blob.raw_size > collapse_limit
end
def too_large?
@@ -73,6 +69,10 @@ module BlobViewer
@too_large = size_limit && blob.raw_size > size_limit
end
+ def binary_detected_after_load?
+ !@initially_binary && blob.binary?
+ end
+
# This method is used on the server side to check whether we can attempt to
# render the blob at all. Human-readable error messages are found in the
# `BlobHelper#blob_render_error_reason` helper.