Skip to content

Commit 6149400

Browse files
committed
prevent accidentally leaving the page when uploading file
1 parent 83c776f commit 6149400

File tree

1 file changed

+13
-3
lines changed
  • public/themes/pterodactyl/js/frontend/files

1 file changed

+13
-3
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,18 @@
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;
2122
var notifyUploadSocketError = false;
2223
uploadSocket = io(Pterodactyl.node.scheme + '://' + Pterodactyl.node.fqdn + ':' + Pterodactyl.node.daemonListen + '/upload/' + Pterodactyl.server.uuid, {
2324
'query': 'token=' + Pterodactyl.server.daemonSecret,
2425
});
2526

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+
2633
uploadSocket.io.on('connect_error', function (err) {
2734
if(typeof notifyUploadSocketError !== 'object') {
2835
notifyUploadSocketError = $.notify({
@@ -77,6 +84,7 @@
7784
});
7885

7986
siofu.addEventListener('start', function (event) {
87+
uploadInProgress = true;
8088
event.file.meta.path = $('#headerTableRow').attr('data-currentdir');
8189
event.file.meta.identifier = Math.random().toString(36).slice(2);
8290

@@ -85,7 +93,7 @@
8593
<td>' + event.file.name + '</td> \
8694
<td colspan=2">&nbsp;</td> \
8795
</tr><tr> \
88-
<td colspan="4" class="has-progress"> \
96+
<td colspan="5" class="has-progress"> \
8997
<div class="progress progress-table-bottom active"> \
9098
<div class="progress-bar progress-bar-info prog-bar-' + event.file.meta.identifier +'" style="width: 0%"></div> \
9199
</div> \
@@ -104,7 +112,8 @@
104112
});
105113

106114
// Do something when a file is uploaded:
107-
siofu.addEventListener('complete', function(event){
115+
siofu.addEventListener('complete', function(event) {
116+
uploadInProgress = false;
108117
if (!event.success) {
109118
$('.prog-bar-' + event.file.meta.identifier).css('width', '100%').removeClass('progress-bar-info').addClass('progress-bar-danger');
110119
$.notify({
@@ -116,7 +125,8 @@
116125
}
117126
});
118127

119-
siofu.addEventListener('error', function(event){
128+
siofu.addEventListener('error', function(event) {
129+
uploadInProgress = false;
120130
console.error(event);
121131
$('.prog-bar-' + event.file.meta.identifier).css('width', '100%').removeClass('progress-bar-info').addClass('progress-bar-danger');
122132
$.notify({

0 commit comments

Comments
 (0)