Skip to content

Commit 72ad6d5

Browse files
committed
Show file upload size limit when uploading files
Also handle errors better.
1 parent a03add7 commit 72ad6d5

File tree

5 files changed

+83
-14
lines changed

5 files changed

+83
-14
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ This file is a running track of new features and fixes to each version of the pa
33

44
This project follows [Semantic Versioning](http://semver.org) guidelines.
55

6+
## v0.5.4 (Bodacious Boreopterus)
7+
### Changed
8+
* File uploads now account for a maximum file size that is assigned for the daemon, and gives cleaner errors when that limit is reached.
9+
* File upload limit can now be controlled from the panel.
10+
611
## v0.5.3 (Bodacious Boreopterus)
712
### Fixed
813
* 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.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class AddConfigurableUploadLimit extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('nodes', function (Blueprint $table) {
17+
$table->unsignedInteger('upload_size')->after('disk_overallocate')->default(100);
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('nodes', function (Blueprint $table) {
29+
$table->dropColumn('upload_size');
30+
});
31+
}
32+
}

resources/views/admin/nodes/view.blade.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,19 @@
216216
</div>
217217
</div>
218218
<div class="panel-heading" style="border-top: 1px solid #ddd;"></div>
219+
<div class="panel-body">
220+
<div class="row">
221+
<div class="form-group col-md-6">
222+
<label for="disk_overallocate" class="control-label">Maximum Web Upload Filesize</label>
223+
<div class="input-group">
224+
<input type="text" name="upload_size" class="form-control" value="{{ old('upload_size', $node->upload_size) }}"/>
225+
<span class="input-group-addon">MB</span>
226+
</div>
227+
<p class="text-muted"><small>Enter the maximum size of files that can be uploaded through the web-based file manager.</small></p>
228+
</div>
229+
</div>
230+
</div>
231+
<div class="panel-heading" style="border-top: 1px solid #ddd;"></div>
219232
<div class="panel-body">
220233
<div class="row">
221234
<div class="col-xs-6">
@@ -310,7 +323,7 @@
310323
"installed": "{{ route('remote.install') }}"
311324
},
312325
"uploads": {
313-
"maximumSize": 100000000
326+
"size_limit": {{ $node->upload_size }}
314327
},
315328
"keys": [
316329
"{{ $node->daemonSecret }}"

resources/views/server/files/add.blade.php

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,11 @@
105105
<div class="alert alert-warning">Edit the path location above <strong>before you upload files</strong>. 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. <em>The directory must exist before performing an upload.</em></div>
106106
<div class="alert alert-danger" id="upload_error" style="display: none;"></div>
107107
<input type="file" id="fileinput" name="fileUpload[]" multiple="" style="display:none;"/>
108-
<div id="uploader_box" class="well well-sm" style="cursor:pointer;">
109-
<center><h2 style="margin-bottom: 25px;">Drag and Drop File Here</h2></center>
108+
<div id="upload_box" class="well well-sm" style="cursor:pointer;">
109+
<center>
110+
<h2 style="margin-bottom: 25px;">Drag and Drop File(s) Here</h2>
111+
<p class="text-muted">The maximum size for web-based file uploads is currently <code>{{ $node->upload_size }} MB</code>.</p>
112+
</center>
110113
</div>
111114
<span id="file_progress"></span>
112115
</div>
@@ -154,16 +157,33 @@
154157
}
155158
});
156159
160+
var dropCounter = 0;
161+
$('#upload_box').bind({
162+
dragenter: function (event) {
163+
event.preventDefault();
164+
dropCounter++;
165+
$(this).addClass('hasFileHover');
166+
},
167+
dragleave: function (event) {
168+
dropCounter--;
169+
if (dropCounter === 0) {
170+
$(this).removeClass('hasFileHover');
171+
}
172+
},
173+
drop: function (event) {
174+
dropCounter = 0;
175+
$(this).removeClass('hasFileHover');
176+
}
177+
});
178+
157179
socket.on('error', function (err) {
158180
console.error('There was an error while attemping to connect to the websocket: ' + err + '\n\nPlease try loading this page again.');
159181
});
160182
161-
162183
var siofu = new SocketIOFileUpload(uploadSocket);
163-
siofu.chunkDelay = 25;
164184
165-
document.getElementById("uploader_box").addEventListener("click", siofu.prompt, false);
166-
siofu.listenOnDrop(document.getElementById("uploader_box"));
185+
document.getElementById("upload_box").addEventListener("click", siofu.prompt, false);
186+
siofu.listenOnDrop(document.getElementById("upload_box"));
167187
168188
siofu.addEventListener('start', function (event) {
169189
event.file.meta.path = $("#u_file_name").val();
@@ -197,13 +217,13 @@
197217
// Do something when a file is uploaded:
198218
siofu.addEventListener('complete', function(event){
199219
if (!event.success) {
200-
$("#upload_error").html('An error was encountered while attempting to upload this file. Does the target directory exist?').show();
220+
$("#upload_error").html('An error was encountered while attempting to upload this file: <strong>' + event.message + '.</strong>').show();
201221
$("#file-upload-" + event.file.meta.identifier).hide();
202222
}
203223
});
204224
205225
siofu.addEventListener('error', function(event){
206-
$("#upload_error").html('An error was encountered while attempting to upload this file. Does the target directory exist?').show();
226+
$("#upload_error").html('An error was encountered while attempting to upload this file: <strong>' + event.message + '.</strong>').show();
207227
$("#file-upload-" + event.file.meta.identifier).hide();
208228
});
209229

resources/views/server/files/index.blade.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<h3 class="panel-title">File Path Information</h3>
5353
</div>
5454
<div class="panel-body">
55-
When configuring any file paths in your server plugins or settings you should use <code>/home/container</code> as your base path.
55+
When configuring any file paths in your server plugins or settings you should use <code>/home/container</code> as your base path. The maximum size for web-based file uploads is currently <code>{{ $node->upload_size }} MB</code>.
5656
</div>
5757
</div>
5858
</div>
@@ -101,8 +101,6 @@
101101
102102
103103
var siofu = new SocketIOFileUpload(uploadSocket);
104-
siofu.chunkDelay = 25;
105-
106104
siofu.listenOnDrop(document.getElementById("upload_box"));
107105
108106
window.addEventListener('dragover', function (event) {
@@ -173,12 +171,13 @@
173171
});
174172
175173
siofu.addEventListener('error', function(event){
174+
console.error(event);
176175
$('.prog-bar-' + event.file.meta.identifier).css('width', '100%').removeClass('progress-bar-info').addClass('progress-bar-danger');
177176
$.notify({
178-
message: 'An error was encountered while attempting to upload this file.'
177+
message: 'An error was encountered while attempting to upload this file: <strong>' + event.message + '.</strong>',
179178
}, {
180179
type: 'danger',
181-
delay: 5000
180+
delay: 8000
182181
});
183182
});
184183
@endcan

0 commit comments

Comments
 (0)