2021-05-06 19:35:43 +00:00
|
|
|
{{template "base" .}}
|
|
|
|
|
|
|
|
{{define "title"}}{{.Title}}{{end}}
|
|
|
|
|
|
|
|
{{define "extra_css"}}
|
|
|
|
<link href="{{.StaticURL}}/vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet">
|
|
|
|
<link href="{{.StaticURL}}/vendor/datatables/buttons.bootstrap4.min.css" rel="stylesheet">
|
|
|
|
<link href="{{.StaticURL}}/vendor/datatables/fixedHeader.bootstrap4.min.css" rel="stylesheet">
|
|
|
|
<link href="{{.StaticURL}}/vendor/datatables/responsive.bootstrap4.min.css" rel="stylesheet">
|
2021-05-30 21:07:46 +00:00
|
|
|
<link href="{{.StaticURL}}/vendor/datatables/dataTables.checkboxes.css" rel="stylesheet">
|
2021-11-25 18:24:32 +00:00
|
|
|
<link href="{{.StaticURL}}/vendor/lightbox2/css/lightbox.min.css" rel="stylesheet">
|
2021-05-30 21:07:46 +00:00
|
|
|
<style>
|
|
|
|
div.dataTables_wrapper span.selected-info,
|
|
|
|
div.dataTables_wrapper span.selected-item {
|
|
|
|
margin-left: 0.5em;
|
|
|
|
}
|
|
|
|
</style>
|
2021-05-06 19:35:43 +00:00
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{define "page_body"}}
|
2021-05-27 07:40:46 +00:00
|
|
|
<div id="errorMsg" class="card mb-4 border-left-warning" style="display: none;">
|
|
|
|
<div id="errorTxt" class="card-body text-form-error"></div>
|
|
|
|
</div>
|
2021-05-06 19:35:43 +00:00
|
|
|
|
|
|
|
<div class="card shadow mb-4">
|
|
|
|
<div class="card-header py-3">
|
|
|
|
<h6 class="m-0 font-weight-bold"><a href="{{.FilesURL}}?path=%2F"><i class="fas fa-home"></i> Home</a> {{range .Paths}}{{if eq .Href ""}}/{{.DirName}}{{else}}<a href="{{.Href}}">/{{.DirName}}</a>{{end}}{{end}}</h6>
|
|
|
|
</div>
|
|
|
|
<div class="card-body">
|
|
|
|
{{if .Error}}
|
|
|
|
<div class="card mb-4 border-left-warning">
|
|
|
|
<div class="card-body text-form-error">{{.Error}}</div>
|
|
|
|
</div>
|
|
|
|
{{end}}
|
|
|
|
<div class="table-responsive">
|
|
|
|
<table class="table table-hover nowrap" id="dataTable" width="100%" cellspacing="0">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
2021-05-30 21:07:46 +00:00
|
|
|
<th></th>
|
2021-05-06 19:35:43 +00:00
|
|
|
<th>Type</th>
|
|
|
|
<th>Name</th>
|
|
|
|
<th>Size</th>
|
|
|
|
<th>Last modified</th>
|
2021-10-09 12:17:28 +00:00
|
|
|
<th></th>
|
2021-12-03 17:33:08 +00:00
|
|
|
<th></th>
|
2021-05-06 19:35:43 +00:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{{end}}
|
|
|
|
|
2021-07-26 18:55:49 +00:00
|
|
|
{{define "dialog"}}
|
2021-10-09 12:17:28 +00:00
|
|
|
<div class="modal fade" id="createDirModal" tabindex="-1" role="dialog" aria-labelledby="createDirModalLabel"
|
2021-07-26 18:55:49 +00:00
|
|
|
aria-hidden="true">
|
|
|
|
<div class="modal-dialog" role="document">
|
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
2021-10-09 12:17:28 +00:00
|
|
|
<h5 class="modal-title" id="createDirModalLabel">
|
2021-07-26 18:55:49 +00:00
|
|
|
Create a new directory
|
|
|
|
</h5>
|
|
|
|
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
|
|
|
|
<span aria-hidden="true">×</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<form id="create_dir_form" action="" method="POST">
|
|
|
|
<div class="modal-body">
|
|
|
|
<div class="form-group">
|
|
|
|
<label for="directory_name" class="col-form-label">Name</label>
|
|
|
|
<input type="text" class="form-control" id="directory_name" required>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
|
|
|
<button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
|
|
|
|
<button type="submit" class="btn btn-primary">Submit</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="modal fade" id="uploadFilesModal" tabindex="-1" role="dialog" aria-labelledby="uploadFilesModalLabel"
|
|
|
|
aria-hidden="true">
|
|
|
|
<div class="modal-dialog" role="document">
|
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
|
|
|
<h5 class="modal-title" id="uploadFilesModalLabel">
|
2021-11-30 17:40:50 +00:00
|
|
|
Upload one or more files
|
2021-07-26 18:55:49 +00:00
|
|
|
</h5>
|
|
|
|
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
|
|
|
|
<span aria-hidden="true">×</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
2021-11-22 11:25:36 +00:00
|
|
|
<form id="upload_files_form" action="{{.FilesURL}}?path={{.CurrentDir}}" method="POST" enctype="multipart/form-data">
|
|
|
|
<div class="modal-body">
|
2021-11-30 17:40:50 +00:00
|
|
|
<input type="file" class="form-control-file" id="files_name" name="filenames" required multiple>
|
2021-07-26 18:55:49 +00:00
|
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
2021-11-30 17:40:50 +00:00
|
|
|
<input type="hidden" name="_form_token" value="{{.CSRFToken}}">
|
2021-07-26 18:55:49 +00:00
|
|
|
<button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
|
|
|
|
<button type="submit" class="btn btn-primary">Submit</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="modal fade" id="renameModal" tabindex="-1" role="dialog" aria-labelledby="renameModalLabel"
|
|
|
|
aria-hidden="true">
|
|
|
|
<div class="modal-dialog" role="document">
|
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
|
|
|
<h5 class="modal-title" id="renameModalLabel">
|
|
|
|
Rename the selected item
|
|
|
|
</h5>
|
|
|
|
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
|
|
|
|
<span aria-hidden="true">×</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<form id="rename_form" action="" method="POST">
|
|
|
|
<div class="modal-body">
|
|
|
|
<div class="form-group">
|
|
|
|
<label for="rename_old_name" class="col-form-label">Old name</label>
|
|
|
|
<input type="text" class="form-control" id="rename_old_name" readonly>
|
|
|
|
</div>
|
2021-12-25 16:13:23 +00:00
|
|
|
<div class="form-group">
|
|
|
|
<label for="rename_new_dir" class="col-form-label">New base dir</label>
|
|
|
|
<input type="text" class="form-control" id="rename_new_dir" required aria-describedby="renameNewDirHelpBlock">
|
|
|
|
<small id="renameNewDirHelpBlock" class="form-text text-muted">
|
|
|
|
Setting a directory other than the current one will move the item there. This directory must exists
|
|
|
|
</small>
|
|
|
|
</div>
|
2021-07-26 18:55:49 +00:00
|
|
|
<div class="form-group">
|
|
|
|
<label for="rename_new_name" class="col-form-label">New name</label>
|
|
|
|
<input type="text" class="form-control" id="rename_new_name" required>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
|
|
|
<button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
|
|
|
|
<button type="submit" class="btn btn-primary">Submit</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel"
|
|
|
|
aria-hidden="true">
|
|
|
|
<div class="modal-dialog" role="document">
|
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
|
|
|
<h5 class="modal-title" id="deleteModalLabel">
|
|
|
|
Confirmation required
|
|
|
|
</h5>
|
|
|
|
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
|
|
|
|
<span aria-hidden="true">×</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
2021-11-30 17:40:50 +00:00
|
|
|
<div class="modal-body">Do you want to delete the selected item/s?</div>
|
2021-07-26 18:55:49 +00:00
|
|
|
<div class="modal-footer">
|
|
|
|
<button class="btn btn-secondary" type="button" data-dismiss="modal">
|
|
|
|
Cancel
|
|
|
|
</button>
|
|
|
|
<a class="btn btn-warning" href="#" onclick="deleteAction()">
|
|
|
|
Delete
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-11-22 11:25:36 +00:00
|
|
|
|
|
|
|
<div class="modal fade" id="spinnerModal" tabindex="-1" role="dialog" data-keyboard="false" data-backdrop="static">
|
|
|
|
<div class="modal-dialog modal-dialog-centered justify-content-center" role="document">
|
|
|
|
<span style="color: #333333;" class="fa fa-spinner fa-spin fa-3x"></span>
|
|
|
|
<!-- <span id="uploadProgress" style="color: #3A3B3C;" class="mx-3"></span> -->
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-07-26 18:55:49 +00:00
|
|
|
{{end}}
|
|
|
|
|
2021-05-06 19:35:43 +00:00
|
|
|
{{define "extra_js"}}
|
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/jquery.dataTables.min.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/dataTables.bootstrap4.min.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/dataTables.buttons.min.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/buttons.bootstrap4.min.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/dataTables.fixedHeader.min.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/dataTables.responsive.min.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/responsive.bootstrap4.min.js"></script>
|
2021-05-30 21:07:46 +00:00
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/dataTables.checkboxes.min.js"></script>
|
2021-11-25 18:24:32 +00:00
|
|
|
<script src="{{.StaticURL}}/vendor/lightbox2/js/lightbox.min.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/pdfobject/pdfobject.min.js"></script>
|
2021-10-09 12:17:28 +00:00
|
|
|
<script src="{{.StaticURL}}/vendor/codemirror/codemirror.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/codemirror/meta.js"></script>
|
2021-12-03 17:33:08 +00:00
|
|
|
{{if .HasIntegrations}}
|
|
|
|
<script type="text/javascript">
|
|
|
|
var childReference = null;
|
|
|
|
var checkerStarted = false;
|
|
|
|
const childProps = new Map();
|
|
|
|
|
|
|
|
function openExternalURL(url, fileLink, fileName){
|
|
|
|
if (childReference == null || childReference.closed) {
|
|
|
|
childProps.set('link', fileLink);
|
|
|
|
childProps.set('url', url);
|
|
|
|
childProps.set('file_name', fileName);
|
|
|
|
childReference = window.open(url, '_blank');
|
|
|
|
if (!checkerStarted){
|
|
|
|
keepAlive();
|
2021-12-04 14:14:44 +00:00
|
|
|
setInterval(checkExternalWindow, 300000);
|
2021-12-03 17:33:08 +00:00
|
|
|
checkerStarted = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$('#errorTxt').text('An external window is already open, please close it before trying to open a new one');
|
|
|
|
$('#errorMsg').show();
|
|
|
|
setTimeout(function () {
|
|
|
|
$('#errorMsg').hide();
|
|
|
|
}, 8000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-08 18:25:22 +00:00
|
|
|
function notifyBlobDownloadError(message) {
|
|
|
|
if (childReference == null || childReference.closed) {
|
|
|
|
console.log("external window null or closed, cannot notify download error");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
childReference.postMessage({
|
|
|
|
type: 'blobDownloadError',
|
|
|
|
message: message
|
|
|
|
}, childProps.get('url'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function notifySave(status, message) {
|
2021-12-03 17:33:08 +00:00
|
|
|
if (childReference == null || childReference.closed) {
|
2021-12-04 14:14:44 +00:00
|
|
|
console.log("external window null or closed, cannot notify save");
|
2021-12-03 17:33:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
childReference.postMessage({
|
|
|
|
type: 'blobSaveResult',
|
|
|
|
status: status,
|
|
|
|
message: message
|
|
|
|
}, childProps.get('url'));
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener('message', (event) => {
|
|
|
|
var url = childProps.get('url');
|
|
|
|
if (!url || !url.startsWith(event.origin)){
|
|
|
|
console.log("origin: "+event.origin+" does not match the expected one: "+url+" refusing message");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (childReference == null || childReference.closed) {
|
2021-12-04 14:14:44 +00:00
|
|
|
console.log("external window null or closed, refusing message");
|
2021-12-03 17:33:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (event.data.type){
|
|
|
|
case 'ready':
|
|
|
|
// the child is ready send some details
|
|
|
|
childReference.postMessage({
|
|
|
|
type: 'readyResponse',
|
|
|
|
user: '{{.LoggedUser.Username}}',
|
|
|
|
file_name: childProps.get('file_name')
|
|
|
|
}, childProps.get('url'));
|
|
|
|
break;
|
|
|
|
case 'sendBlob':
|
2021-12-08 18:25:22 +00:00
|
|
|
// we have to download the blob, this could require some time so
|
2021-12-03 17:33:08 +00:00
|
|
|
// we first send a blobDownloadStart message so the child can
|
|
|
|
// show a spinner or something similar
|
2021-12-08 18:25:22 +00:00
|
|
|
var errorMessage = "Error downloading file";
|
2021-12-03 17:33:08 +00:00
|
|
|
childReference.postMessage({
|
|
|
|
type: 'blobDownloadStart'
|
|
|
|
}, childProps.get('url'));
|
2021-12-08 18:25:22 +00:00
|
|
|
// download the file and send it as blob to the child window
|
|
|
|
async function downloadFileAsBlob(){
|
|
|
|
var errorMessage = "Error downloading file";
|
|
|
|
let response;
|
|
|
|
try {
|
|
|
|
response = await fetch(childProps.get('link'),{
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-TOKEN': '{{.CSRFToken}}'
|
|
|
|
},
|
|
|
|
credentials: 'same-origin',
|
|
|
|
redirect: 'error'
|
|
|
|
});
|
|
|
|
} catch (e){
|
|
|
|
throw Error(errorMessage+": " +e.message);
|
|
|
|
}
|
|
|
|
if (response.status == 200){
|
|
|
|
let responseBlob;
|
|
|
|
try {
|
|
|
|
responseBlob = await response.blob();
|
|
|
|
} catch (e){
|
|
|
|
throw Error(errorMessage+" as blob: " +e.message);
|
|
|
|
}
|
2021-12-03 17:33:08 +00:00
|
|
|
let fileBlob = new File([responseBlob], childProps.get('file_name'), {type: responseBlob.type, lastModified: ""});
|
|
|
|
childReference.postMessage({
|
|
|
|
type: 'blob',
|
|
|
|
file: fileBlob
|
|
|
|
}, childProps.get('url'));
|
2021-12-08 18:25:22 +00:00
|
|
|
} else {
|
|
|
|
let jsonResponse;
|
|
|
|
try {
|
|
|
|
jsonResponse = await response.json();
|
|
|
|
} catch(e){
|
|
|
|
throw Error(errorMessage);
|
|
|
|
}
|
|
|
|
if (jsonResponse.message) {
|
|
|
|
errorMessage = jsonResponse.message;
|
|
|
|
}
|
|
|
|
if (jsonResponse.error) {
|
|
|
|
errorMessage += ": " + jsonResponse.error;
|
|
|
|
}
|
|
|
|
throw Error(errorMessage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
downloadFileAsBlob().catch(function(error){
|
|
|
|
notifyBlobDownloadError(error.message);
|
|
|
|
$('#errorTxt').text(error.message);
|
|
|
|
$('#errorMsg').show();
|
|
|
|
setTimeout(function () {
|
|
|
|
$('#errorMsg').hide();
|
|
|
|
}, 5000);
|
|
|
|
});
|
2021-12-03 17:33:08 +00:00
|
|
|
break;
|
|
|
|
case 'saveBlob':
|
|
|
|
spinnerDone = false;
|
2021-12-08 18:25:22 +00:00
|
|
|
$('#spinnerModal').modal('show');
|
|
|
|
|
|
|
|
async function saveBlob() {
|
|
|
|
var errorMessage = "Error saving external file";
|
|
|
|
var uploadPath = '{{.FileURL}}?path={{.CurrentDir}}'+encodeURIComponent("/"+childProps.get('file_name'));
|
|
|
|
let response;
|
|
|
|
try {
|
|
|
|
response = await fetch(uploadPath, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-TOKEN': '{{.CSRFToken}}'
|
|
|
|
},
|
|
|
|
credentials: 'same-origin',
|
|
|
|
redirect: 'error',
|
|
|
|
body: event.data.file
|
|
|
|
});
|
|
|
|
} catch (e){
|
|
|
|
throw Error(errorMessage+": " +e.message);
|
|
|
|
}
|
|
|
|
if (response.status == 201){
|
2021-12-03 17:33:08 +00:00
|
|
|
$('#spinnerModal').modal('hide');
|
|
|
|
notifySave("OK", "");
|
|
|
|
setTimeout(function () {
|
|
|
|
location.reload();
|
|
|
|
}, 2000);
|
2021-12-08 18:25:22 +00:00
|
|
|
} else {
|
|
|
|
let jsonResponse;
|
|
|
|
try {
|
|
|
|
jsonResponse = await response.json();
|
|
|
|
} catch(e){
|
|
|
|
throw Error(errorMessage);
|
2021-12-03 17:33:08 +00:00
|
|
|
}
|
2021-12-08 18:25:22 +00:00
|
|
|
if (jsonResponse.message) {
|
|
|
|
errorMessage = jsonResponse.message;
|
|
|
|
}
|
|
|
|
if (jsonResponse.error) {
|
|
|
|
errorMessage += ": " + jsonResponse.error;
|
|
|
|
}
|
|
|
|
throw Error(errorMessage);
|
2021-12-03 17:33:08 +00:00
|
|
|
}
|
2021-12-08 18:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
saveBlob().catch(function(error){
|
|
|
|
$('#spinnerModal').modal('hide');
|
|
|
|
notifySave("KO", error.message);
|
|
|
|
$('#errorTxt').text(error.message);
|
|
|
|
$('#errorMsg').show();
|
|
|
|
setTimeout(function () {
|
|
|
|
$('#errorMsg').hide();
|
|
|
|
}, 5000);
|
2021-12-03 17:33:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.log("Unsupported message: "+JSON.stringify(event.data));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function checkExternalWindow() {
|
|
|
|
if (childReference == null || childReference.closed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
keepAlive();
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
{{end}}
|
2021-05-06 19:35:43 +00:00
|
|
|
<script type="text/javascript">
|
2021-11-30 17:40:50 +00:00
|
|
|
var spinnerDone = false;
|
2021-05-27 07:40:46 +00:00
|
|
|
|
2021-12-10 17:43:26 +00:00
|
|
|
var escapeHTML = function ( t ) {
|
|
|
|
return t
|
|
|
|
.replace( /&/g, '&' )
|
|
|
|
.replace( /</g, '<' )
|
|
|
|
.replace( />/g, '>' )
|
|
|
|
.replace( /"/g, '"' );
|
|
|
|
};
|
|
|
|
|
|
|
|
function shortenData(d, cutoff) {
|
|
|
|
if ( typeof d !== 'string' ) {
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( d.length <= cutoff ) {
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
var shortened = d.substr(0, cutoff-1);
|
|
|
|
return shortened+'…';
|
|
|
|
}
|
|
|
|
|
2021-05-27 07:40:46 +00:00
|
|
|
function getIconForFile(filename) {
|
2021-05-30 21:07:46 +00:00
|
|
|
var extension = filename.slice((filename.lastIndexOf(".") - 1 >>> 0) + 2).toLowerCase();
|
|
|
|
switch (extension) {
|
|
|
|
case "doc":
|
|
|
|
case "docx":
|
|
|
|
case "odt":
|
|
|
|
case "wps":
|
|
|
|
return "far fa-file-word";
|
|
|
|
case "ppt":
|
|
|
|
case "pptx":
|
|
|
|
return "far fa-file-powerpoint";
|
|
|
|
case "xls":
|
|
|
|
case "xlsx":
|
|
|
|
case "ods":
|
|
|
|
return "far fa-file-excel";
|
|
|
|
case "pdf":
|
|
|
|
return "far fa-file-pdf";
|
|
|
|
case "webm":
|
|
|
|
case "mkv":
|
|
|
|
case "flv":
|
|
|
|
case "vob":
|
|
|
|
case "ogv":
|
|
|
|
case "ogg":
|
|
|
|
case "avi":
|
|
|
|
case "ts":
|
|
|
|
case "mov":
|
|
|
|
case "wmv":
|
|
|
|
case "asf":
|
|
|
|
case "mpeg":
|
|
|
|
case "mpv":
|
|
|
|
case "3gp":
|
|
|
|
return "far fa-file-video";
|
|
|
|
case "jpeg":
|
|
|
|
case "jpg":
|
|
|
|
case "png":
|
|
|
|
case "gif":
|
|
|
|
case "webp":
|
|
|
|
case "tiff":
|
|
|
|
case "psd":
|
|
|
|
case "bmp":
|
|
|
|
case "svg":
|
|
|
|
case "jp2":
|
|
|
|
return "far fa-file-image";
|
|
|
|
case "go":
|
|
|
|
case "sh":
|
|
|
|
case "bat":
|
|
|
|
case "java":
|
|
|
|
case "php":
|
|
|
|
case "cs":
|
|
|
|
case "asp":
|
|
|
|
case "aspx":
|
|
|
|
case "css":
|
|
|
|
case "html":
|
|
|
|
case "xhtml":
|
|
|
|
case "htm":
|
|
|
|
case "js":
|
|
|
|
case "jsp":
|
|
|
|
case "py":
|
|
|
|
case "rb":
|
|
|
|
case "cgi":
|
|
|
|
case "c":
|
|
|
|
case "cpp":
|
|
|
|
case "h":
|
|
|
|
case "hpp":
|
|
|
|
case "kt":
|
|
|
|
case "ktm":
|
|
|
|
case "kts":
|
|
|
|
case "swift":
|
|
|
|
case "r":
|
|
|
|
return "far fa-file-code";
|
|
|
|
case "zip":
|
|
|
|
case "zipx":
|
|
|
|
case "rar":
|
|
|
|
case "tar":
|
|
|
|
case "gz":
|
|
|
|
case "bz2":
|
|
|
|
case "zstd":
|
|
|
|
case "zst":
|
|
|
|
case "sz":
|
|
|
|
case "lz":
|
|
|
|
case "lz4":
|
|
|
|
case "xz":
|
|
|
|
case "jar":
|
|
|
|
return "far fa-file-archive";
|
|
|
|
case "txt":
|
|
|
|
case "rtf":
|
|
|
|
case "json":
|
|
|
|
case "xml":
|
|
|
|
case "yaml":
|
|
|
|
case "toml":
|
|
|
|
case "log":
|
|
|
|
case "csv":
|
|
|
|
case "ini":
|
|
|
|
case "cfg":
|
|
|
|
return "far fa-file-alt";
|
|
|
|
default:
|
|
|
|
return "far fa-file";
|
2021-05-27 07:40:46 +00:00
|
|
|
}
|
2021-05-30 21:07:46 +00:00
|
|
|
}
|
2021-05-27 07:40:46 +00:00
|
|
|
|
2021-10-09 12:17:28 +00:00
|
|
|
function getNameFromMeta(meta) {
|
|
|
|
return meta.split('_').slice(1).join('_');
|
2021-07-26 18:55:49 +00:00
|
|
|
}
|
|
|
|
|
2021-10-09 12:17:28 +00:00
|
|
|
function getTypeFromMeta(meta) {
|
|
|
|
return meta.split('_')[0];
|
2021-07-26 18:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteAction() {
|
|
|
|
var table = $('#dataTable').DataTable();
|
|
|
|
table.button('delete:name').enable(false);
|
2021-11-30 17:40:50 +00:00
|
|
|
|
|
|
|
var selectedItems = table.column(0).checkboxes.selected()
|
|
|
|
var has_errors = false;
|
|
|
|
var index = 0;
|
|
|
|
var success = 0;
|
|
|
|
spinnerDone = false;
|
|
|
|
|
2021-07-26 18:55:49 +00:00
|
|
|
$('#deleteModal').modal('hide');
|
2021-11-30 17:40:50 +00:00
|
|
|
$('#spinnerModal').modal('show');
|
|
|
|
|
|
|
|
function deleteItem() {
|
|
|
|
if (index >= selectedItems.length || has_errors){
|
|
|
|
$('#spinnerModal').modal('hide');
|
|
|
|
spinnerDone = true;
|
|
|
|
if (!has_errors){
|
|
|
|
location.reload();
|
2021-12-28 11:03:52 +00:00
|
|
|
} else {
|
|
|
|
table.button('delete:name').enable(true);
|
2021-11-30 17:40:50 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var selected = selectedItems[index];
|
|
|
|
var itemType = getTypeFromMeta(selected);
|
|
|
|
var itemName = getNameFromMeta(selected);
|
|
|
|
var path;
|
|
|
|
if (itemType == "1"){
|
|
|
|
path = '{{.DirsURL}}';
|
|
|
|
} else {
|
|
|
|
path = '{{.FilesURL}}';
|
|
|
|
}
|
2021-12-08 18:25:22 +00:00
|
|
|
path+='?path={{.CurrentDir}}'+encodeURIComponent("/"+itemName);
|
2021-11-30 17:40:50 +00:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: path,
|
|
|
|
type: 'DELETE',
|
|
|
|
dataType: 'json',
|
|
|
|
headers: { 'X-CSRF-TOKEN': '{{.CSRFToken}}' },
|
|
|
|
timeout: 60000,
|
|
|
|
success: function (result) {
|
|
|
|
index++;
|
|
|
|
success++;
|
|
|
|
deleteItem();
|
|
|
|
},
|
|
|
|
error: function ($xhr, textStatus, errorThrown) {
|
|
|
|
index++;
|
|
|
|
has_errors = true;
|
|
|
|
var txt = "Unable to delete the selected item/s";
|
|
|
|
if (success > 0){
|
|
|
|
txt = "Not all the selected items have been deleted, please reload the page";
|
|
|
|
}
|
|
|
|
if ($xhr) {
|
|
|
|
var json = $xhr.responseJSON;
|
|
|
|
if (json) {
|
|
|
|
if (json.message) {
|
|
|
|
txt = json.message;
|
|
|
|
}
|
|
|
|
if (json.error) {
|
|
|
|
txt += ": " + json.error;
|
|
|
|
}
|
2021-07-26 18:55:49 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-30 17:40:50 +00:00
|
|
|
$('#errorTxt').text(txt);
|
|
|
|
$('#errorMsg').show();
|
|
|
|
setTimeout(function () {
|
|
|
|
$('#errorMsg').hide();
|
|
|
|
}, 10000);
|
|
|
|
deleteItem();
|
2021-07-26 18:55:49 +00:00
|
|
|
}
|
2021-11-30 17:40:50 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteItem();
|
2021-07-26 18:55:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-22 11:25:36 +00:00
|
|
|
function keepAlive() {
|
|
|
|
$.ajax({
|
|
|
|
url: '{{.ProfileURL}}',
|
|
|
|
timeout: 15000
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-05-06 19:35:43 +00:00
|
|
|
$(document).ready(function () {
|
2021-11-30 17:40:50 +00:00
|
|
|
$('#spinnerModal').on('shown.bs.modal', function () {
|
|
|
|
if (spinnerDone){
|
|
|
|
$('#spinnerModal').modal('hide');
|
|
|
|
}
|
|
|
|
});
|
2021-07-26 18:55:49 +00:00
|
|
|
$("#create_dir_form").submit(function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
$('#createDirModal').modal('hide');
|
|
|
|
var dirName = replaceSlash($("#directory_name").val());
|
2021-12-08 18:25:22 +00:00
|
|
|
var path = '{{.DirsURL}}?path={{.CurrentDir}}' + encodeURIComponent("/"+dirName);
|
2021-07-26 18:55:49 +00:00
|
|
|
$.ajax({
|
|
|
|
url: path,
|
|
|
|
type: 'POST',
|
|
|
|
dataType: 'json',
|
|
|
|
headers: { 'X-CSRF-TOKEN': '{{.CSRFToken}}' },
|
|
|
|
timeout: 15000,
|
|
|
|
success: function (result) {
|
|
|
|
location.reload();
|
|
|
|
},
|
|
|
|
error: function ($xhr, textStatus, errorThrown) {
|
|
|
|
var txt = "Unable to create the requested directory";
|
|
|
|
if ($xhr) {
|
|
|
|
var json = $xhr.responseJSON;
|
|
|
|
if (json) {
|
|
|
|
if (json.message) {
|
|
|
|
txt = json.message;
|
|
|
|
}
|
|
|
|
if (json.error) {
|
|
|
|
txt += ": " + json.error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$('#errorTxt').text(txt);
|
|
|
|
$('#errorMsg').show();
|
|
|
|
setTimeout(function () {
|
|
|
|
$('#errorMsg').hide();
|
|
|
|
}, 5000);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#upload_files_form").submit(function (event){
|
|
|
|
event.preventDefault();
|
2021-12-03 17:33:08 +00:00
|
|
|
keepAlive();
|
2021-12-04 14:14:44 +00:00
|
|
|
var keepAliveTimer = setInterval(keepAlive, 300000);
|
2021-11-30 17:40:50 +00:00
|
|
|
|
|
|
|
var files = $("#files_name")[0].files;
|
|
|
|
var has_errors = false;
|
|
|
|
var index = 0;
|
|
|
|
var success = 0;
|
|
|
|
spinnerDone = false;
|
|
|
|
|
|
|
|
$('#uploadFilesModal').modal('hide');
|
|
|
|
$('#spinnerModal').modal('show');
|
|
|
|
|
|
|
|
function uploadFile() {
|
|
|
|
if (index >= files.length || has_errors){
|
|
|
|
//console.log("upload done, index: "+index+" has errors: "+has_errors+" ok: "+success);
|
2021-11-22 11:25:36 +00:00
|
|
|
clearInterval(keepAliveTimer);
|
|
|
|
$('#spinnerModal').modal('hide');
|
2021-11-30 17:40:50 +00:00
|
|
|
spinnerDone = true;
|
|
|
|
if (!has_errors){
|
|
|
|
location.reload();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2021-12-08 18:25:22 +00:00
|
|
|
|
|
|
|
async function saveFile() {
|
|
|
|
//console.log("save file, index: "+index);
|
|
|
|
var errorMessage = "Error uploading files";
|
|
|
|
let response;
|
|
|
|
try {
|
|
|
|
var f = files[index];
|
|
|
|
var uploadPath = '{{.FileURL}}?path={{.CurrentDir}}'+encodeURIComponent("/"+f.name);
|
2021-12-10 17:43:26 +00:00
|
|
|
var lastModified;
|
|
|
|
try {
|
|
|
|
lastModified = f.lastModified;
|
|
|
|
} catch (e) {
|
|
|
|
console.log("unable to get last modified time from file: "+e.message);
|
|
|
|
lastModified = "";
|
|
|
|
}
|
2021-12-08 18:25:22 +00:00
|
|
|
response = await fetch(uploadPath, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
2021-12-10 17:43:26 +00:00
|
|
|
'X-SFTPGO-MTIME': lastModified,
|
2021-12-08 18:25:22 +00:00
|
|
|
'X-CSRF-TOKEN': '{{.CSRFToken}}'
|
|
|
|
},
|
|
|
|
credentials: 'same-origin',
|
|
|
|
redirect: 'error',
|
|
|
|
body: f
|
|
|
|
});
|
|
|
|
} catch (e){
|
|
|
|
throw Error(errorMessage+": " +e.message);
|
|
|
|
}
|
|
|
|
if (response.status == 201){
|
2021-11-30 17:40:50 +00:00
|
|
|
index++;
|
|
|
|
success++;
|
|
|
|
uploadFile();
|
2021-12-08 18:25:22 +00:00
|
|
|
} else {
|
|
|
|
let jsonResponse;
|
|
|
|
try {
|
|
|
|
jsonResponse = await response.json();
|
|
|
|
} catch(e){
|
|
|
|
throw Error(errorMessage);
|
2021-11-30 17:40:50 +00:00
|
|
|
}
|
2021-12-08 18:25:22 +00:00
|
|
|
if (jsonResponse.message) {
|
|
|
|
errorMessage = jsonResponse.message;
|
2021-07-26 18:55:49 +00:00
|
|
|
}
|
2021-12-08 18:25:22 +00:00
|
|
|
if (jsonResponse.error) {
|
|
|
|
errorMessage += ": " + jsonResponse.error;
|
|
|
|
}
|
|
|
|
throw Error(errorMessage);
|
2021-07-26 18:55:49 +00:00
|
|
|
}
|
2021-12-08 18:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
saveFile().catch(function(error){
|
|
|
|
index++;
|
|
|
|
has_errors = true;
|
|
|
|
$('#errorTxt').text(error.message);
|
|
|
|
$('#errorMsg').show();
|
|
|
|
setTimeout(function () {
|
|
|
|
$('#errorMsg').hide();
|
|
|
|
}, 10000);
|
|
|
|
uploadFile();
|
2021-11-30 17:40:50 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
uploadFile();
|
2021-07-26 18:55:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$("#rename_form").submit(function (event){
|
|
|
|
event.preventDefault();
|
|
|
|
var table = $('#dataTable').DataTable();
|
|
|
|
table.button('rename:name').enable(false);
|
|
|
|
var selected = table.column(0).checkboxes.selected()[0];
|
2021-10-09 12:17:28 +00:00
|
|
|
var itemType = getTypeFromMeta(selected);
|
|
|
|
var itemName = getNameFromMeta(selected);
|
2021-07-26 18:55:49 +00:00
|
|
|
var targetName = replaceSlash($("#rename_new_name").val());
|
2021-12-25 16:13:23 +00:00
|
|
|
var targetDir = $("#rename_new_dir").val();
|
|
|
|
if (targetDir != "/") {
|
|
|
|
targetDir = targetDir.endsWith('/') ? targetDir.slice(0, -1) : targetDir;
|
|
|
|
}
|
|
|
|
if (targetDir.trim() == ""){
|
|
|
|
targetDir = "{{.CurrentDir}}";
|
|
|
|
} else {
|
|
|
|
targetDir = encodeURIComponent(targetDir);
|
|
|
|
}
|
2021-07-26 18:55:49 +00:00
|
|
|
var path;
|
|
|
|
if (itemType == "1"){
|
|
|
|
path = '{{.DirsURL}}';
|
|
|
|
} else {
|
|
|
|
path = '{{.FilesURL}}';
|
|
|
|
}
|
2021-12-25 16:13:23 +00:00
|
|
|
path+='?path={{.CurrentDir}}'+encodeURIComponent("/"+itemName)+'&target='+targetDir+encodeURIComponent("/"+targetName);
|
|
|
|
$('#renameModal').modal('hide');
|
2021-07-26 18:55:49 +00:00
|
|
|
$.ajax({
|
|
|
|
url: path,
|
|
|
|
type: 'PATCH',
|
|
|
|
dataType: 'json',
|
|
|
|
headers: { 'X-CSRF-TOKEN': '{{.CSRFToken}}' },
|
|
|
|
timeout: 15000,
|
|
|
|
success: function (result) {
|
|
|
|
location.reload();
|
|
|
|
},
|
|
|
|
error: function ($xhr, textStatus, errorThrown) {
|
|
|
|
var txt = "Error renaming item";
|
|
|
|
if ($xhr) {
|
|
|
|
var json = $xhr.responseJSON;
|
|
|
|
if (json) {
|
|
|
|
if (json.message) {
|
|
|
|
txt = json.message;
|
|
|
|
}
|
|
|
|
if (json.error) {
|
|
|
|
txt += ": " + json.error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$('#errorTxt').text(txt);
|
|
|
|
$('#errorMsg').show();
|
|
|
|
setTimeout(function () {
|
|
|
|
$('#errorMsg').hide();
|
2021-12-28 11:03:52 +00:00
|
|
|
}, 8000);
|
|
|
|
var selectedItems = table.column(0).checkboxes.selected().length;
|
|
|
|
table.button('rename:name').enable(selectedItems == 1);
|
2021-07-26 18:55:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-05-06 19:35:43 +00:00
|
|
|
$.fn.dataTable.ext.buttons.refresh = {
|
|
|
|
text: '<i class="fas fa-sync-alt"></i>',
|
|
|
|
name: 'refresh',
|
|
|
|
titleAttr: "Refresh",
|
|
|
|
action: function (e, dt, node, config) {
|
|
|
|
location.reload();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-30 21:07:46 +00:00
|
|
|
$.fn.dataTable.ext.buttons.download = {
|
|
|
|
text: '<i class="fas fa-download"></i>',
|
|
|
|
name: 'download',
|
2021-06-05 14:07:09 +00:00
|
|
|
titleAttr: "Download Zip",
|
2021-05-30 21:07:46 +00:00
|
|
|
action: function (e, dt, node, config) {
|
|
|
|
var filesArray = [];
|
|
|
|
var selected = dt.column(0).checkboxes.selected();
|
|
|
|
for (i = 0; i < selected.length; i++) {
|
2021-10-09 12:17:28 +00:00
|
|
|
filesArray.push(getNameFromMeta(selected[i]));
|
2021-05-30 21:07:46 +00:00
|
|
|
}
|
2021-12-08 18:25:22 +00:00
|
|
|
var files = encodeURIComponent(JSON.stringify(filesArray));
|
2021-05-30 21:07:46 +00:00
|
|
|
var downloadURL = '{{.DownloadURL}}';
|
|
|
|
var currentDir = '{{.CurrentDir}}';
|
2021-08-03 17:58:03 +00:00
|
|
|
var ts = new Date().getTime().toString();
|
|
|
|
window.location = `${downloadURL}?path=${currentDir}&files=${files}&_=${ts}`;
|
2021-05-30 21:07:46 +00:00
|
|
|
},
|
|
|
|
enabled: false
|
|
|
|
};
|
|
|
|
|
2021-07-26 18:55:49 +00:00
|
|
|
$.fn.dataTable.ext.buttons.addFiles = {
|
|
|
|
text: '<i class="fas fa-file-upload"></i>',
|
|
|
|
name: 'addFiles',
|
|
|
|
titleAttr: "Upload files",
|
|
|
|
action: function (e, dt, node, config) {
|
2021-11-30 17:40:50 +00:00
|
|
|
document.getElementById("files_name").value = null;
|
2021-07-26 18:55:49 +00:00
|
|
|
$('#uploadFilesModal').modal('show');
|
|
|
|
},
|
|
|
|
enabled: true
|
|
|
|
};
|
|
|
|
|
|
|
|
$.fn.dataTable.ext.buttons.addDirectory = {
|
|
|
|
text: '<i class="fas fa-folder-plus"></i>',
|
|
|
|
name: 'addDirectory',
|
|
|
|
titleAttr: "Add directory",
|
|
|
|
action: function (e, dt, node, config) {
|
|
|
|
$("#directory_name").val("");
|
|
|
|
$('#createDirModal').modal('show');
|
|
|
|
},
|
|
|
|
enabled: true
|
|
|
|
};
|
|
|
|
|
|
|
|
$.fn.dataTable.ext.buttons.rename = {
|
2021-10-09 12:17:28 +00:00
|
|
|
text: '<i class="fas fa-pen"></i>',
|
2021-07-26 18:55:49 +00:00
|
|
|
name: 'rename',
|
|
|
|
titleAttr: "Rename",
|
|
|
|
action: function (e, dt, node, config) {
|
|
|
|
var selected = table.column(0).checkboxes.selected()[0];
|
2021-10-09 12:17:28 +00:00
|
|
|
var itemName = getNameFromMeta(selected);
|
2021-07-26 18:55:49 +00:00
|
|
|
$("#rename_old_name").val(itemName);
|
2021-12-25 16:13:23 +00:00
|
|
|
$("#rename_new_dir").val(decodeURIComponent("{{.CurrentDir}}".replace(/\+/g, '%20')));
|
2021-07-26 18:55:49 +00:00
|
|
|
$("#rename_new_name").val("");
|
|
|
|
$('#renameModal').modal('show');
|
|
|
|
},
|
|
|
|
enabled: false
|
|
|
|
};
|
|
|
|
|
|
|
|
$.fn.dataTable.ext.buttons.delete = {
|
|
|
|
text: '<i class="fas fa-trash"></i>',
|
|
|
|
name: 'delete',
|
|
|
|
titleAttr: "Delete",
|
|
|
|
action: function (e, dt, node, config) {
|
|
|
|
$('#deleteModal').modal('show');
|
|
|
|
},
|
|
|
|
enabled: false
|
|
|
|
};
|
|
|
|
|
2021-11-06 13:13:20 +00:00
|
|
|
$.fn.dataTable.ext.buttons.share = {
|
|
|
|
text: '<i class="fas fa-share-alt"></i>',
|
|
|
|
name: 'share',
|
|
|
|
titleAttr: "Share",
|
|
|
|
action: function (e, dt, node, config) {
|
|
|
|
var filesArray = [];
|
|
|
|
var selected = dt.column(0).checkboxes.selected();
|
|
|
|
for (i = 0; i < selected.length; i++) {
|
|
|
|
filesArray.push(getNameFromMeta(selected[i]));
|
|
|
|
}
|
2021-12-08 18:25:22 +00:00
|
|
|
var files = encodeURIComponent(JSON.stringify(filesArray));
|
2021-11-06 13:13:20 +00:00
|
|
|
var shareURL = '{{.ShareURL}}';
|
|
|
|
var currentDir = '{{.CurrentDir}}';
|
|
|
|
var ts = new Date().getTime().toString();
|
|
|
|
window.location = `${shareURL}?path=${currentDir}&files=${files}&_=${ts}`;
|
|
|
|
},
|
|
|
|
enabled: false
|
|
|
|
};
|
|
|
|
|
2021-05-06 19:35:43 +00:00
|
|
|
var table = $('#dataTable').DataTable({
|
2021-05-27 07:40:46 +00:00
|
|
|
"ajax": {
|
2021-07-26 18:55:49 +00:00
|
|
|
"url": "{{.DirsURL}}?path={{.CurrentDir}}",
|
2021-05-27 07:40:46 +00:00
|
|
|
"dataSrc": "",
|
|
|
|
"error": function ($xhr, textStatus, errorThrown) {
|
|
|
|
$(".dataTables_processing").hide();
|
|
|
|
var txt = "Failed to get directory listing";
|
|
|
|
if ($xhr) {
|
|
|
|
var json = $xhr.responseJSON;
|
|
|
|
if (json) {
|
2021-06-08 11:24:28 +00:00
|
|
|
if (json.message){
|
|
|
|
txt += ": " + json.message;
|
|
|
|
} else {
|
|
|
|
txt += ": " + json.error;
|
|
|
|
}
|
2021-05-27 07:40:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$('#errorTxt').text(txt);
|
|
|
|
$('#errorMsg').show();
|
|
|
|
setTimeout(function () {
|
|
|
|
$('#errorMsg').hide();
|
|
|
|
}, 10000);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"deferRender": true,
|
|
|
|
"processing": true,
|
2021-12-04 06:58:49 +00:00
|
|
|
"lengthMenu": [ 10, 25, 50, 100, 250, 500 ],
|
|
|
|
"stateSave": true,
|
|
|
|
"stateDuration": 0,
|
|
|
|
"stateSaveParams": function (settings, data) {
|
|
|
|
data.sftpgo_dir = '{{.CurrentDir}}';
|
|
|
|
},
|
|
|
|
"stateLoadParams": function (settings, data) {
|
|
|
|
if (!data.sftpgo_dir || data.sftpgo_dir != '{{.CurrentDir}}'){
|
|
|
|
data.start = 0;
|
|
|
|
data.search.search = "";
|
|
|
|
}
|
2022-04-25 19:58:53 +00:00
|
|
|
data.checkboxes = [];
|
2021-12-04 06:58:49 +00:00
|
|
|
},
|
2021-05-27 07:40:46 +00:00
|
|
|
"columns": [
|
2021-10-09 12:17:28 +00:00
|
|
|
{ "data": "meta" },
|
2021-05-27 07:40:46 +00:00
|
|
|
{ "data": "type" },
|
|
|
|
{
|
|
|
|
"data": "name",
|
2021-05-30 21:07:46 +00:00
|
|
|
"render": function (data, type, row) {
|
2021-05-27 07:40:46 +00:00
|
|
|
if (type === 'display') {
|
2021-12-10 17:43:26 +00:00
|
|
|
var title = "";
|
|
|
|
var cssClass = "";
|
|
|
|
var shortened = shortenData(data, 70);
|
|
|
|
if (shortened != data){
|
|
|
|
title = escapeHTML(data);
|
|
|
|
cssClass = "ellipsis";
|
|
|
|
}
|
|
|
|
|
2021-05-30 21:07:46 +00:00
|
|
|
if (row["type"] == "1") {
|
2021-12-10 17:43:26 +00:00
|
|
|
return `<i class="fas fa-folder"></i> <a class="${cssClass}" href="${row['url']}" title="${title}">${shortened}</a>`;
|
2021-05-27 07:40:46 +00:00
|
|
|
}
|
2021-05-30 21:07:46 +00:00
|
|
|
if (row["size"] == "") {
|
2021-12-10 17:43:26 +00:00
|
|
|
return `<i class="fas fa-external-link-alt"></i> <a class="${cssClass}" href="${row['url']}" title="${title}">${shortened}</a>`;
|
2021-05-30 21:07:46 +00:00
|
|
|
}
|
|
|
|
var icon = getIconForFile(data);
|
2021-12-10 17:43:26 +00:00
|
|
|
return `<i class="${icon}"></i> <a class="${cssClass}" href="${row['url']}" title="${title}">${shortened}</a>`;
|
2021-05-27 07:40:46 +00:00
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ "data": "size" },
|
2021-10-09 12:17:28 +00:00
|
|
|
{ "data": "last_modified" },
|
|
|
|
{ "data": "edit_url",
|
|
|
|
"render": function (data, type, row) {
|
|
|
|
if (type === 'display') {
|
2021-11-25 18:24:32 +00:00
|
|
|
var filename = row["name"];
|
|
|
|
var extension = filename.slice((filename.lastIndexOf(".") - 1 >>> 0) + 2).toLowerCase();
|
2021-12-03 17:33:08 +00:00
|
|
|
if (data){
|
2021-10-09 12:17:28 +00:00
|
|
|
if (extension == "csv" || extension == "bat" || CodeMirror.findModeByExtension(extension) != null){
|
2021-11-25 18:24:32 +00:00
|
|
|
{{if .CanAddFiles}}
|
2021-10-09 12:17:28 +00:00
|
|
|
return `<a href="${data}"><i class="fas fa-edit"></i></a>`;
|
2021-11-25 18:24:32 +00:00
|
|
|
{{else}}
|
|
|
|
return `<a href="${data}"><i class="fas fa-eye"></i></a>`;
|
|
|
|
{{end}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (row["type"] == "2") {
|
|
|
|
switch (extension) {
|
|
|
|
case "jpeg":
|
|
|
|
case "jpg":
|
|
|
|
case "png":
|
|
|
|
case "gif":
|
|
|
|
case "webp":
|
|
|
|
case "bmp":
|
|
|
|
case "svg":
|
|
|
|
case "ico":
|
|
|
|
var view_url = row['url']+"&inline=1";
|
|
|
|
return `<a href="${view_url}" data-lightbox="${filename}" data-title="${filename}"><i class="fas fa-eye"></i></a>`;
|
|
|
|
case "pdf":
|
|
|
|
if (PDFObject.supportsPDFs){
|
|
|
|
var view_url = row['url'];
|
|
|
|
view_url = view_url.replace('{{.FilesURL}}','{{.ViewPDFURL}}');
|
|
|
|
return `<a href="${view_url}" target="_blank"><i class="fas fa-eye"></i></a>`;
|
|
|
|
}
|
2021-10-09 12:17:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
2021-12-03 17:33:08 +00:00
|
|
|
},
|
|
|
|
{ "data": "ext_url",
|
|
|
|
"render": function (data, type, row) {
|
|
|
|
{{if .HasIntegrations}}
|
|
|
|
if (type === 'display') {
|
|
|
|
if (data){
|
2021-12-08 18:25:22 +00:00
|
|
|
return `<a href="#" onclick="openExternalURL('${data}', '${row["ext_link"]}', '${row["name"]}');"><i class="fas fa-external-link-alt"></i></a>`;
|
2021-12-03 17:33:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
{{end}}
|
|
|
|
return "";
|
|
|
|
}
|
2021-10-09 12:17:28 +00:00
|
|
|
}
|
2021-05-27 07:40:46 +00:00
|
|
|
],
|
2021-05-06 19:35:43 +00:00
|
|
|
"buttons": [],
|
|
|
|
"lengthChange": false,
|
|
|
|
"columnDefs": [
|
|
|
|
{
|
|
|
|
"targets": [0],
|
2021-05-30 21:07:46 +00:00
|
|
|
"checkboxes": {
|
|
|
|
"selectCallback": function (nodes, selected) {
|
|
|
|
var selectedItems = table.column(0).checkboxes.selected().length;
|
|
|
|
var selectedText = "";
|
|
|
|
if (selectedItems == 1) {
|
|
|
|
selectedText = "1 item selected";
|
|
|
|
} else if (selectedItems > 1) {
|
|
|
|
selectedText = `${selectedItems} items selected`;
|
|
|
|
}
|
2021-11-06 13:13:20 +00:00
|
|
|
{{if .CanDownload}}
|
2021-05-30 21:07:46 +00:00
|
|
|
table.button('download:name').enable(selectedItems > 0);
|
2021-11-06 13:13:20 +00:00
|
|
|
{{end}}
|
2021-07-26 18:55:49 +00:00
|
|
|
{{if .CanRename}}
|
|
|
|
table.button('rename:name').enable(selectedItems == 1);
|
|
|
|
{{end}}
|
|
|
|
{{if .CanDelete}}
|
2021-11-30 17:40:50 +00:00
|
|
|
table.button('delete:name').enable(selectedItems > 0);
|
2021-07-26 18:55:49 +00:00
|
|
|
{{end}}
|
2021-11-06 13:13:20 +00:00
|
|
|
{{if .CanShare}}
|
|
|
|
table.button('share:name').enable(selectedItems > 0);
|
|
|
|
{{end}}
|
2021-05-30 21:07:46 +00:00
|
|
|
$('#dataTable_info').find('span').remove();
|
|
|
|
$("#dataTable_info").append('<span class="selected-info"><span class="selected-item">' + selectedText + '</span></span>');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"orderable": false,
|
|
|
|
"searchable": false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"targets": [1],
|
2021-05-06 19:35:43 +00:00
|
|
|
"visible": false,
|
|
|
|
"searchable": false
|
|
|
|
},
|
|
|
|
{
|
2021-05-30 21:07:46 +00:00
|
|
|
"targets": [3, 4],
|
2021-05-06 19:35:43 +00:00
|
|
|
"searchable": false
|
2021-10-09 12:17:28 +00:00
|
|
|
},
|
|
|
|
{
|
2021-12-03 17:33:08 +00:00
|
|
|
"targets": [5, 6],
|
2021-10-09 12:17:28 +00:00
|
|
|
"orderable": false,
|
|
|
|
"searchable": false
|
2021-05-06 19:35:43 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"scrollX": false,
|
|
|
|
"scrollY": false,
|
|
|
|
"responsive": true,
|
|
|
|
"language": {
|
2021-05-27 07:40:46 +00:00
|
|
|
"processing": '<i class="fas fa-spinner fa-spin fa-3x fa-fw"></i><span class="sr-only">Loading...</span>',
|
|
|
|
"loadingRecords": "",
|
2021-05-07 18:41:20 +00:00
|
|
|
"emptyTable": "No files or folders"
|
2021-05-06 19:35:43 +00:00
|
|
|
},
|
2021-05-30 21:07:46 +00:00
|
|
|
"initComplete": function (settings, json) {
|
|
|
|
table.button().add(0, 'refresh');
|
|
|
|
table.button().add(0, 'pageLength');
|
2021-11-06 13:13:20 +00:00
|
|
|
{{if .CanShare}}
|
|
|
|
table.button().add(0, 'share');
|
|
|
|
{{end}}
|
2021-08-03 17:58:03 +00:00
|
|
|
{{if .CanDownload}}
|
2021-05-30 21:07:46 +00:00
|
|
|
table.button().add(0, 'download');
|
2021-08-03 17:58:03 +00:00
|
|
|
{{end}}
|
2021-07-26 18:55:49 +00:00
|
|
|
{{if .CanDelete}}
|
|
|
|
table.button().add(0, 'delete');
|
|
|
|
{{end}}
|
|
|
|
{{if .CanRename}}
|
|
|
|
table.button().add(0, 'rename');
|
|
|
|
{{end}}
|
|
|
|
{{if .CanCreateDirs}}
|
|
|
|
table.button().add(0, 'addDirectory');
|
|
|
|
{{end}}
|
|
|
|
{{if .CanAddFiles}}
|
|
|
|
table.button().add(0, 'addFiles');
|
|
|
|
{{end}}
|
2021-10-09 12:17:28 +00:00
|
|
|
table.buttons().container().appendTo('.col-md-6:eq(0)', table.table().container());
|
2021-05-27 07:40:46 +00:00
|
|
|
},
|
2021-05-30 21:07:46 +00:00
|
|
|
"orderFixed": [1, 'asc'],
|
|
|
|
"order": [[2, 'asc']]
|
2021-05-06 19:35:43 +00:00
|
|
|
});
|
|
|
|
|
2021-05-30 21:07:46 +00:00
|
|
|
new $.fn.dataTable.FixedHeader(table);
|
2021-05-27 07:40:46 +00:00
|
|
|
$.fn.dataTable.ext.errMode = 'none';
|
2021-05-06 19:35:43 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
{{end}}
|