Skip to content

Commit da92796

Browse files
committed
Better file upload handling, add touch target
1 parent 6149400 commit da92796

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

public/themes/pterodactyl/js/frontend/files/src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class FileManager {
4949
}
5050
});
5151
$('#internal_alert').slideUp();
52+
53+
if (typeof Siofu === 'object') {
54+
Siofu.listenOnInput(document.getElementById("files_touch_target"));
55+
}
5256
}).fail(jqXHR => {
5357
this.loader(false);
5458
if (_.isFunction(next)) {

public/themes/pterodactyl/js/frontend/files/upload.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,11 @@
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
// SOFTWARE.
2020
(function initUploader() {
21-
var uploadInProgress = false;
2221
var notifyUploadSocketError = false;
2322
uploadSocket = io(Pterodactyl.node.scheme + '://' + Pterodactyl.node.fqdn + ':' + Pterodactyl.node.daemonListen + '/upload/' + Pterodactyl.server.uuid, {
2423
'query': 'token=' + Pterodactyl.server.daemonSecret,
2524
});
2625

27-
window.onbeforeunload = function () {
28-
if (uploadInProgress) {
29-
return "An upload is in progress. Navigating away will abort this upload, are you sure you want to continue?";
30-
}
31-
}
32-
3326
uploadSocket.io.on('connect_error', function (err) {
3427
if(typeof notifyUploadSocketError !== 'object') {
3528
notifyUploadSocketError = $.notify({
@@ -42,7 +35,7 @@
4235
});
4336

4437
uploadSocket.on('error', err => {
45-
siofu.destroy();
38+
Siofu.destroy();
4639
console.error(err);
4740
});
4841

@@ -53,8 +46,12 @@
5346
}
5447
});
5548

56-
var siofu = new SocketIOFileUpload(uploadSocket);
57-
siofu.listenOnDrop(document.getElementById("load_files"));
49+
window.Siofu = new SocketIOFileUpload(uploadSocket);
50+
Siofu.listenOnDrop(document.getElementById("load_files"));
51+
52+
if (document.getElementById("files_touch_target")) {
53+
Siofu.listenOnInput(document.getElementById("files_touch_target"));
54+
}
5855

5956
window.addEventListener('dragover', function (event) {
6057
event.preventDefault();
@@ -83,8 +80,10 @@
8380
}
8481
});
8582

86-
siofu.addEventListener('start', function (event) {
87-
uploadInProgress = true;
83+
Siofu.addEventListener('start', function (event) {
84+
window.onbeforeunload = function () {
85+
return 'A file upload in in progress, are you sure you want to continue?';
86+
};
8887
event.file.meta.path = $('#headerTableRow').attr('data-currentdir');
8988
event.file.meta.identifier = Math.random().toString(36).slice(2);
9089

@@ -102,7 +101,10 @@
102101
');
103102
});
104103

105-
siofu.addEventListener('progress', function(event) {
104+
Siofu.addEventListener('progress', function(event) {
105+
window.onbeforeunload = function () {
106+
return 'A file upload in in progress, are you sure you want to continue?';
107+
};
106108
var percent = event.bytesLoaded / event.file.size * 100;
107109
if (percent >= 100) {
108110
$('.prog-bar-' + event.file.meta.identifier).css('width', '100%').removeClass('progress-bar-info').addClass('progress-bar-success').parent().removeClass('active');
@@ -112,8 +114,8 @@
112114
});
113115

114116
// Do something when a file is uploaded:
115-
siofu.addEventListener('complete', function(event) {
116-
uploadInProgress = false;
117+
Siofu.addEventListener('complete', function(event) {
118+
window.onbeforeunload = function () {};
117119
if (!event.success) {
118120
$('.prog-bar-' + event.file.meta.identifier).css('width', '100%').removeClass('progress-bar-info').addClass('progress-bar-danger');
119121
$.notify({
@@ -125,8 +127,8 @@
125127
}
126128
});
127129

128-
siofu.addEventListener('error', function(event) {
129-
uploadInProgress = false;
130+
Siofu.addEventListener('error', function(event) {
131+
window.onbeforeunload = function () {};
130132
console.error(event);
131133
$('.prog-bar-' + event.file.meta.identifier).css('width', '100%').removeClass('progress-bar-info').addClass('progress-bar-danger');
132134
$.notify({

resources/themes/pterodactyl/server/files/list.blade.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
<th style="width:55%">@lang('server.files.file_name')</th>
2525
<th style="width:15%">@lang('server.files.size')</th>
2626
<th style="width:20%">@lang('server.files.last_modified')</th>
27-
<th style="width:8%"></th>
27+
<th style="width:8%">
28+
<label class="btn btn-primary btn-xs btn-file">
29+
Upload <input type="file" id="files_touch_target" style="display: none;"/>
30+
</label>
31+
</th>
2832
</tr>
2933
<tr id="headerTableRow" data-currentdir="{{ $directory['header'] }}">
3034
<th><i class="fa fa-folder-open"></i></th>

0 commit comments

Comments
 (0)