From 802bcd8cbd03d426ea8429ccecc25852f3abea97 Mon Sep 17 00:00:00 2001 From: "Allen.Guo" <5418150+toddlerya@users.noreply.github.com> Date: Tue, 1 Jan 2019 09:22:09 +0800 Subject: [PATCH 1/3] set threshold for large files (#558) --- lib/file.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/file.go b/lib/file.go index 8501fb6d..d37c104e 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 int64 = 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" { + 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 { From 7394f6b9bbe554d03a4e31a6bb03db2991097750 Mon Sep 17 00:00:00 2001 From: helloray Date: Tue, 1 Jan 2019 09:39:45 +0800 Subject: [PATCH 2/3] fix multi-select files download error when filename contains '+' (#571) --- lib/http/download.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/http/download.go b/lib/http/download.go index d2143646..48c0a494 100644 --- a/lib/http/download.go +++ b/lib/http/download.go @@ -30,7 +30,7 @@ func downloadHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int if len(names) != 0 { for _, name := range names { // Unescape the name. - name, err := url.QueryUnescape(name) + name, err := url.QueryUnescape(strings.Replace(name, "+", "%2B", -1)) if err != nil { return http.StatusInternalServerError, err } From 0b66d700e8e2fac3bf7b707494228a7a27d65e5b Mon Sep 17 00:00:00 2001 From: 1138-4EB <1138-4EB@users.noreply.github.com> Date: Tue, 1 Jan 2019 03:18:58 +0100 Subject: [PATCH 3/3] allow to set default user with env vars (#591) --- lib/filebrowser.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) mode change 100644 => 100755 lib/filebrowser.go diff --git a/lib/filebrowser.go b/lib/filebrowser.go old mode 100644 new mode 100755 index caad4357..9d2b7601 --- a/lib/filebrowser.go +++ b/lib/filebrowser.go @@ -19,6 +19,7 @@ import ( "github.com/hacdias/fileutils" "github.com/mholt/caddy" "github.com/robfig/cron" + "github.com/spf13/viper" ) const ( @@ -205,14 +206,18 @@ func (m *FileBrowser) Setup() error { // If there are no users in the database, it creates a new one // based on 'base' User that must be provided by the function caller. if len(users) == 0 { - u := *m.DefaultUser - u.Username = "admin" + viper.SetDefault("DEFAULT_USERNAME", "admin") // Hashes the password. - u.Password, err = HashPassword("admin") + defaultPassword, err := HashPassword("admin") if err != nil { return err } + viper.SetDefault("DEFAULT_PASSWORD_HASH", defaultPassword) + + u := *m.DefaultUser + u.Username = viper.GetString("DEFAULT_USERNAME") + u.Password = viper.GetString("DEFAULT_PASSWORD_HASH") // The first user must be an administrator. u.Admin = true