Skip to content

Commit 9c7b753

Browse files
committed
Complete code for new file manager
1 parent 4d922b6 commit 9c7b753

File tree

4 files changed

+111
-11
lines changed

4 files changed

+111
-11
lines changed

public/themes/default/css/pterodactyl.css

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,5 +233,16 @@ li.btn.btn-default.pill:active,li.btn.btn-default.pill:focus,li.btn.btn-default.
233233
.dropdown-menu > li.bg-default > a {
234234
padding-left: 11px !important;
235235
}
236-
/*.bg-danger:active,.bg-danger:focus,.bg-danger:hover{color:#fff;background-color:#d32a0e;border-color:#b1240c}
237-
.bg-danger.disabled,.bg-danger.disabled:active,.bg-danger.disabled:focus,.bg-danger.disabled:hover,.bg-danger[disabled]{background-color:#f04124;border-color:#ea2f10}*/
236+
237+
.success.pulsate {
238+
animation: pulse 3s infinite;
239+
}
240+
241+
@keyframes pulse {
242+
0% {
243+
background-color: #fff;
244+
}
245+
100% {
246+
background-color: #dff0d8;
247+
}
248+
}

resources/views/server/js/filemanager/actions.blade.php

Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ActionsClass {
5151
'X-Access-Server': '{{ $server->uuid }}'
5252
},
5353
contentType: 'application/json; charset=utf-8',
54-
url: '{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/files/rename',
54+
url: '{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/file/rename',
5555
timeout: 10000,
5656
data: JSON.stringify({
5757
from: `${currentPath}${currentName}`,
@@ -77,10 +77,11 @@ class ActionsClass {
7777
}
7878

7979
download() {
80-
var baseURL = $(this.menu).find('li[data-action="download"] a').attr('href');
81-
var toURL = baseURL + $(this.element).find('td[data-identifier="name"]').data('name');
80+
const nameBlock = $(this.element).find('td[data-identifier="name"]');
81+
const fileName = decodeURIComponent(nameBlock.attr('data-name'));
82+
const filePath = decodeURIComponent(nameBlock.data('path'));
8283

83-
window.location = toURL;
84+
window.location = `/server/{{ $server->uuidShort }}/files/download/${filePath}${fileName}`;
8485
}
8586

8687
rename() {
@@ -128,7 +129,7 @@ class ActionsClass {
128129
'X-Access-Server': '{{ $server->uuid }}'
129130
},
130131
contentType: 'application/json; charset=utf-8',
131-
url: '{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/files/rename',
132+
url: '{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/file/rename',
132133
timeout: 10000,
133134
data: JSON.stringify({
134135
from: `${currentPath}${currentName}`,
@@ -184,7 +185,7 @@ class ActionsClass {
184185
}, () => {
185186
$.ajax({
186187
type: 'DELETE',
187-
url: `{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/file/${delPath}${delName}`,
188+
url: `{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/file/f/${delPath}${delName}`,
188189
headers: {
189190
'X-Access-Token': '{{ $server->daemonSecret }}',
190191
'X-Access-Server': '{{ $server->uuid }}'
@@ -206,4 +207,77 @@ class ActionsClass {
206207
});
207208
});
208209
}
210+
211+
decompress() {
212+
const nameBlock = $(this.element).find('td[data-identifier="name"]');
213+
const compPath = decodeURIComponent(nameBlock.data('path'));
214+
const compName = decodeURIComponent(nameBlock.data('name'));
215+
216+
$.ajax({
217+
type: 'POST',
218+
url: `{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/file/decompress`,
219+
headers: {
220+
'X-Access-Token': '{{ $server->daemonSecret }}',
221+
'X-Access-Server': '{{ $server->uuid }}'
222+
},
223+
contentType: 'application/json; charset=utf-8',
224+
data: JSON.stringify({
225+
files: `${compPath}${compName}`
226+
})
227+
}).done(data => {
228+
Files.list(compPath);
229+
}).fail(jqXHR => {
230+
console.error(jqXHR);
231+
var error = 'An error occured while trying to process this request.';
232+
if (typeof jqXHR.responseJSON !== 'undefined' && typeof jqXHR.responseJSON.error !== 'undefined') {
233+
error = jqXHR.responseJSON.error;
234+
}
235+
swal({
236+
type: 'error',
237+
title: 'Whoops!',
238+
html: true,
239+
text: error
240+
});
241+
});
242+
}
243+
244+
compress() {
245+
const nameBlock = $(this.element).find('td[data-identifier="name"]');
246+
const compPath = decodeURIComponent(nameBlock.data('path'));
247+
const compName = decodeURIComponent(nameBlock.data('name'));
248+
249+
$.ajax({
250+
type: 'POST',
251+
url: `{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/file/compress`,
252+
headers: {
253+
'X-Access-Token': '{{ $server->daemonSecret }}',
254+
'X-Access-Server': '{{ $server->uuid }}'
255+
},
256+
contentType: 'application/json; charset=utf-8',
257+
data: JSON.stringify({
258+
files: `${compPath}${compName}`,
259+
to: compPath.toString()
260+
})
261+
}).done(data => {
262+
Files.list(compPath, err => {
263+
if (err) return;
264+
const fileListing = $('#file_listing').find(`[data-name="${data.saved_as}"]`).parent();
265+
fileListing.addClass('success pulsate').delay(3000).queue(() => {
266+
fileListing.removeClass('success pulsate').dequeue();
267+
});
268+
});
269+
}).fail(jqXHR => {
270+
console.error(jqXHR);
271+
var error = 'An error occured while trying to process this request.';
272+
if (typeof jqXHR.responseJSON !== 'undefined' && typeof jqXHR.responseJSON.error !== 'undefined') {
273+
error = jqXHR.responseJSON.error;
274+
}
275+
swal({
276+
type: 'error',
277+
title: 'Whoops!',
278+
html: true,
279+
text: error
280+
});
281+
});
282+
}
209283
}

resources/views/server/js/filemanager/contextmenu.blade.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ContextMenuClass {
3838
<li data-action="compress" class="hidden"><a tabindex="-1" href="#"><i class="fa fa-file-archive-o"></i> Compress</a></li> \
3939
<li data-action="decompress" class="hidden"><a tabindex="-1" href="#"><i class="fa fa-expand"></i> Decompress</a></li> \
4040
<li class="divider"></li> \
41-
<li data-action="download" class="hidden"><a tabindex="-1" href="/server/{{ $server->uuidShort }}/files/download/"><i class="fa fa-download"></i> Download</a></li> \
41+
<li data-action="download" class="hidden"><a tabindex="-1" href="#"><i class="fa fa-download"></i> Download</a></li> \
4242
<li data-action="delete" class="bg-danger"><a tabindex="-1" href="#"><i class="fa fa-trash-o"></i> Delete</a></li> \
4343
</ul>';
4444
}
@@ -86,6 +86,16 @@ class ContextMenuClass {
8686
Actions.rename();
8787
});
8888

89+
$(menu).find('li[data-action="compress"]').unbind().on('click', e => {
90+
e.preventDefault();
91+
Actions.compress();
92+
});
93+
94+
$(menu).find('li[data-action="decompress"]').unbind().on('click', e => {
95+
e.preventDefault();
96+
Actions.decompress();
97+
});
98+
8999
$(menu).find('li[data-action="download"]').unbind().on('click', e => {
90100
e.preventDefault();
91101
Actions.download();

resources/views/server/js/filemanager/index.blade.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class FileManager {
2424
this.list(this.decodeHash());
2525
}
2626

27-
list(path, isError) {
27+
list(path, next) {
2828
if (_.isUndefined(path)) {
2929
path = this.decodeHash();
3030
}
@@ -43,16 +43,21 @@ class FileManager {
4343
this.loader(false);
4444
$('#load_files').slideUp().html(data).slideDown(100, () => {
4545
ContextMenu.run();
46+
if (_.isFunction(next)) {
47+
return next();
48+
}
4649
});
4750
$('#internal_alert').slideUp();
4851
}).fail(jqXHR => {
4952
this.loader(false);
53+
if (_.isFunction(next)) {
54+
return next(new Error('Failed to load file listing.'));
55+
}
5056
swal({
5157
type: 'error',
5258
title: 'File Error',
5359
text: 'An error occured while attempting to process this request. Please try again.',
5460
});
55-
if (!isError) this.list('/', true);
5661
console.log(jqXHR);
5762
})
5863
}

0 commit comments

Comments
 (0)