From 72ad6d5c879b28b3a9092ec7818f83339cdfd7d0 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Thu, 1 Dec 2016 18:32:05 -0500 Subject: [PATCH] Show file upload size limit when uploading files Also handle errors better. --- CHANGELOG.md | 5 +++ ...1_173018_add_configurable_upload_limit.php | 32 +++++++++++++++++ resources/views/admin/nodes/view.blade.php | 15 +++++++- resources/views/server/files/add.blade.php | 36 ++++++++++++++----- resources/views/server/files/index.blade.php | 9 +++-- 5 files changed, 83 insertions(+), 14 deletions(-) create mode 100644 database/migrations/2016_12_01_173018_add_configurable_upload_limit.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 41e834a2f..622528589 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ This file is a running track of new features and fixes to each version of the pa This project follows [Semantic Versioning](http://semver.org) guidelines. +## v0.5.4 (Bodacious Boreopterus) +### Changed +* File uploads now account for a maximum file size that is assigned for the daemon, and gives cleaner errors when that limit is reached. +* File upload limit can now be controlled from the panel. + ## v0.5.3 (Bodacious Boreopterus) ### Fixed * Fixed an error that occurred when viewing a node listing when no nodes were created yet due to a mis-declared variable. Also fixes a bug that would have all nodes trying to connect to the daemon using the same secret token on the node listing, causing only the last node to display properly. diff --git a/database/migrations/2016_12_01_173018_add_configurable_upload_limit.php b/database/migrations/2016_12_01_173018_add_configurable_upload_limit.php new file mode 100644 index 000000000..91ef1fbbd --- /dev/null +++ b/database/migrations/2016_12_01_173018_add_configurable_upload_limit.php @@ -0,0 +1,32 @@ +unsignedInteger('upload_size')->after('disk_overallocate')->default(100); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('nodes', function (Blueprint $table) { + $table->dropColumn('upload_size'); + }); + } +} diff --git a/resources/views/admin/nodes/view.blade.php b/resources/views/admin/nodes/view.blade.php index 79203f153..df81a56ed 100644 --- a/resources/views/admin/nodes/view.blade.php +++ b/resources/views/admin/nodes/view.blade.php @@ -216,6 +216,19 @@
+
+
+
+ +
+ + MB +
+

Enter the maximum size of files that can be uploaded through the web-based file manager.

+
+
+
+
@@ -310,7 +323,7 @@ "installed": "{{ route('remote.install') }}" }, "uploads": { - "maximumSize": 100000000 + "size_limit": {{ $node->upload_size }} }, "keys": [ "{{ $node->daemonSecret }}" diff --git a/resources/views/server/files/add.blade.php b/resources/views/server/files/add.blade.php index 7019c0cdc..62cff9719 100644 --- a/resources/views/server/files/add.blade.php +++ b/resources/views/server/files/add.blade.php @@ -105,8 +105,11 @@
Edit the path location above before you upload files. They will automatically be placed in the directory you specify above. You can change this each time you upload a new file without having to press anything else. The directory must exist before performing an upload.
-
-

Drag and Drop File Here

+
+
+

Drag and Drop File(s) Here

+

The maximum size for web-based file uploads is currently {{ $node->upload_size }} MB.

+
@@ -154,16 +157,33 @@ $(window).load(function () { } }); + var dropCounter = 0; + $('#upload_box').bind({ + dragenter: function (event) { + event.preventDefault(); + dropCounter++; + $(this).addClass('hasFileHover'); + }, + dragleave: function (event) { + dropCounter--; + if (dropCounter === 0) { + $(this).removeClass('hasFileHover'); + } + }, + drop: function (event) { + dropCounter = 0; + $(this).removeClass('hasFileHover'); + } + }); + socket.on('error', function (err) { console.error('There was an error while attemping to connect to the websocket: ' + err + '\n\nPlease try loading this page again.'); }); - var siofu = new SocketIOFileUpload(uploadSocket); - siofu.chunkDelay = 25; - document.getElementById("uploader_box").addEventListener("click", siofu.prompt, false); - siofu.listenOnDrop(document.getElementById("uploader_box")); + document.getElementById("upload_box").addEventListener("click", siofu.prompt, false); + siofu.listenOnDrop(document.getElementById("upload_box")); siofu.addEventListener('start', function (event) { event.file.meta.path = $("#u_file_name").val(); @@ -197,13 +217,13 @@ $(window).load(function () { // Do something when a file is uploaded: siofu.addEventListener('complete', function(event){ if (!event.success) { - $("#upload_error").html('An error was encountered while attempting to upload this file. Does the target directory exist?').show(); + $("#upload_error").html('An error was encountered while attempting to upload this file: ' + event.message + '.').show(); $("#file-upload-" + event.file.meta.identifier).hide(); } }); siofu.addEventListener('error', function(event){ - $("#upload_error").html('An error was encountered while attempting to upload this file. Does the target directory exist?').show(); + $("#upload_error").html('An error was encountered while attempting to upload this file: ' + event.message + '.').show(); $("#file-upload-" + event.file.meta.identifier).hide(); }); diff --git a/resources/views/server/files/index.blade.php b/resources/views/server/files/index.blade.php index c284faf60..c664414ba 100644 --- a/resources/views/server/files/index.blade.php +++ b/resources/views/server/files/index.blade.php @@ -52,7 +52,7 @@

File Path Information

- When configuring any file paths in your server plugins or settings you should use /home/container as your base path. + When configuring any file paths in your server plugins or settings you should use /home/container as your base path. The maximum size for web-based file uploads is currently {{ $node->upload_size }} MB.
@@ -101,8 +101,6 @@ $(window).load(function () { var siofu = new SocketIOFileUpload(uploadSocket); - siofu.chunkDelay = 25; - siofu.listenOnDrop(document.getElementById("upload_box")); window.addEventListener('dragover', function (event) { @@ -173,12 +171,13 @@ $(window).load(function () { }); siofu.addEventListener('error', function(event){ + console.error(event); $('.prog-bar-' + event.file.meta.identifier).css('width', '100%').removeClass('progress-bar-info').addClass('progress-bar-danger'); $.notify({ - message: 'An error was encountered while attempting to upload this file.' + message: 'An error was encountered while attempting to upload this file: ' + event.message + '.', }, { type: 'danger', - delay: 5000 + delay: 8000 }); }); @endcan