From e9b744267907857c2a63cb764b2ad2ab1126ca23 Mon Sep 17 00:00:00 2001 From: tddlerya Date: Mon, 19 Nov 2018 14:49:56 +0800 Subject: [PATCH] make the textExtensionsRenderMaxSize number be either a constant, fix filebrowser#556 --- lib/file.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/file.go b/lib/file.go index 6960ef4b..162c5d8b 100644 --- a/lib/file.go +++ b/lib/file.go @@ -23,6 +23,10 @@ import ( "github.com/maruel/natural" ) +// The size of the loaded text can be rendered in the browser. Avoiding files that are too large causes browsers to crash. +// Currently set to 10MB, 10 * 1024 * 1024 = 10485760 byte +const textExtensionsRenderMaxSize int = 10485760 + // File contains the information about a particular file or directory. type File struct { // Indicates the Kind of view on the front-end (Listing, editor or preview). @@ -268,7 +272,7 @@ func (i *File) GetFileType(checkContent bool) error { End: // If the file type is text, save its content. - if i.Type == "text" && i.Size <= 10240 { // Avoiding files that are too large causes browsers to crash + if i.Type == "text" && i.Size <= textExtensionsRenderMaxSize { // Avoiding files that are too large causes browsers to crash if len(content) == 0 { content, err = ioutil.ReadFile(i.Path) if err != nil {