2022-07-18 11:43:25 +00:00
|
|
|
<!--
|
|
|
|
Copyright (C) 2019-2022 Nicola Murino
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, version 3.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
-->
|
2022-02-06 15:46: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">
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{define "page_body"}}
|
|
|
|
<div class="card shadow my-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 id="errorMsg" class="card mb-4 border-left-warning" style="display: none;">
|
|
|
|
<div id="errorTxt" class="card-body text-form-error"></div>
|
|
|
|
</div>
|
|
|
|
<div class="table-responsive">
|
|
|
|
<table class="table table-hover nowrap" id="dataTable" width="100%" cellspacing="0">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Type</th>
|
|
|
|
<th>Name</th>
|
|
|
|
<th>Size</th>
|
|
|
|
<th>Last modified</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{{end}}
|
2022-05-09 17:09:43 +00:00
|
|
|
{{define "dialog"}}
|
|
|
|
<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">
|
|
|
|
Upload one or more files
|
|
|
|
</h5>
|
|
|
|
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
|
|
|
|
<span aria-hidden="true">×</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<form id="upload_files_form" action="{{.FilesURL}}?path={{.CurrentDir}}" method="POST" enctype="multipart/form-data">
|
|
|
|
<div class="modal-body">
|
|
|
|
<input type="file" class="form-control-file" id="files_name" name="filenames" required multiple>
|
|
|
|
</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="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>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{{end}}
|
2022-02-06 15:46: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>
|
|
|
|
<script type="text/javascript">
|
|
|
|
function shortenData(d, cutoff) {
|
|
|
|
if ( typeof d !== 'string' ) {
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( d.length <= cutoff ) {
|
2022-09-12 18:09:14 +00:00
|
|
|
return escapeHTML(d);
|
2022-02-06 15:46:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var shortened = d.substr(0, cutoff-1);
|
2022-09-12 18:09:14 +00:00
|
|
|
return escapeHTML(shortened)+'…';
|
2022-02-06 15:46:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getIconForFile(filename) {
|
|
|
|
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":
|
2022-07-23 14:30:27 +00:00
|
|
|
case "mp4":
|
2022-02-06 15:46:43 +00:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function () {
|
2022-05-09 17:09:43 +00:00
|
|
|
$('#spinnerModal').on('shown.bs.modal', function () {
|
|
|
|
if (spinnerDone){
|
|
|
|
$('#spinnerModal').modal('hide');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#upload_files_form").submit(function (event){
|
|
|
|
event.preventDefault();
|
|
|
|
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){
|
|
|
|
$('#spinnerModal').modal('hide');
|
|
|
|
spinnerDone = true;
|
|
|
|
if (!has_errors){
|
|
|
|
location.reload();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function saveFile() {
|
|
|
|
var errorMessage = "Error uploading files";
|
|
|
|
let response;
|
|
|
|
try {
|
|
|
|
var f = files[index];
|
2022-09-12 18:09:14 +00:00
|
|
|
var uploadPath = '{{.UploadBaseURL}}'+fixedEncodeURIComponent("/"+escapeHTML(f.name));
|
2022-05-09 17:09:43 +00:00
|
|
|
var lastModified;
|
|
|
|
try {
|
|
|
|
lastModified = f.lastModified;
|
|
|
|
} catch (e) {
|
|
|
|
console.log("unable to get last modified time from file: "+e.message);
|
|
|
|
lastModified = "";
|
|
|
|
}
|
|
|
|
response = await fetch(uploadPath, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'X-SFTPGO-MTIME': lastModified
|
|
|
|
},
|
|
|
|
credentials: 'same-origin',
|
|
|
|
redirect: 'error',
|
|
|
|
body: f
|
|
|
|
});
|
|
|
|
} catch (e){
|
|
|
|
throw Error(errorMessage+": " +e.message);
|
|
|
|
}
|
|
|
|
if (response.status == 201){
|
|
|
|
index++;
|
|
|
|
success++;
|
|
|
|
uploadFile();
|
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
saveFile().catch(function(error){
|
|
|
|
index++;
|
|
|
|
has_errors = true;
|
|
|
|
$('#errorTxt').text(error.message);
|
|
|
|
$('#errorMsg').show();
|
|
|
|
setTimeout(function () {
|
|
|
|
$('#errorMsg').hide();
|
|
|
|
}, 10000);
|
|
|
|
uploadFile();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
uploadFile();
|
|
|
|
});
|
|
|
|
|
2022-02-06 15:46: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();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$.fn.dataTable.ext.buttons.download = {
|
|
|
|
text: '<i class="fas fa-download"></i>',
|
|
|
|
name: 'download',
|
|
|
|
titleAttr: "Download the whole share as zip",
|
|
|
|
action: function (e, dt, node, config) {
|
|
|
|
var downloadURL = '{{.DownloadURL}}';
|
|
|
|
var ts = new Date().getTime().toString();
|
|
|
|
window.location = `${downloadURL}?_=${ts}`;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-05-09 17:09:43 +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) {
|
|
|
|
document.getElementById("files_name").value = null;
|
|
|
|
$('#uploadFilesModal').modal('show');
|
|
|
|
},
|
|
|
|
enabled: true
|
|
|
|
};
|
|
|
|
|
2022-02-06 15:46:43 +00:00
|
|
|
var table = $('#dataTable').DataTable({
|
|
|
|
"ajax": {
|
|
|
|
"url": "{{.DirsURL}}?path={{.CurrentDir}}",
|
|
|
|
"dataSrc": "",
|
|
|
|
"error": function ($xhr, textStatus, errorThrown) {
|
|
|
|
$(".dataTables_processing").hide();
|
|
|
|
var txt = "Failed to get directory listing";
|
|
|
|
if ($xhr) {
|
|
|
|
var json = $xhr.responseJSON;
|
|
|
|
if (json) {
|
|
|
|
if (json.message){
|
|
|
|
txt += ": " + json.message;
|
|
|
|
} else {
|
|
|
|
txt += ": " + json.error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$('#errorTxt').text(txt);
|
|
|
|
$('#errorMsg').show();
|
|
|
|
setTimeout(function () {
|
|
|
|
$('#errorMsg').hide();
|
|
|
|
}, 10000);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"deferRender": true,
|
|
|
|
"processing": true,
|
|
|
|
"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 = "";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"columns": [
|
|
|
|
{ "data": "type" },
|
|
|
|
{
|
|
|
|
"data": "name",
|
|
|
|
"render": function (data, type, row) {
|
|
|
|
if (type === 'display') {
|
|
|
|
var title = "";
|
|
|
|
var cssClass = "";
|
|
|
|
var shortened = shortenData(data, 70);
|
2022-09-12 18:09:14 +00:00
|
|
|
data = escapeHTML(data);
|
2022-02-06 15:46:43 +00:00
|
|
|
if (shortened != data){
|
|
|
|
title = escapeHTML(data);
|
|
|
|
cssClass = "ellipsis";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (row["type"] == "1") {
|
|
|
|
return `<i class="fas fa-folder"></i> <a class="${cssClass}" href="${row['url']}" title="${title}">${shortened}</a>`;
|
|
|
|
}
|
|
|
|
if (row["size"] == "") {
|
|
|
|
return `<i class="fas fa-external-link-alt"></i> <a class="${cssClass}" href="${row['url']}" title="${title}">${shortened}</a>`;
|
|
|
|
}
|
|
|
|
var icon = getIconForFile(data);
|
|
|
|
return `<i class="${icon}"></i> <a class="${cssClass}" href="${row['url']}" title="${title}">${shortened}</a>`;
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ "data": "size" },
|
|
|
|
{ "data": "last_modified" }
|
|
|
|
],
|
|
|
|
"buttons": [],
|
2022-05-22 09:45:49 +00:00
|
|
|
"lengthChange": true,
|
2022-02-06 15:46:43 +00:00
|
|
|
"columnDefs": [
|
|
|
|
{
|
|
|
|
"targets": [0],
|
|
|
|
"visible": false,
|
|
|
|
"searchable": false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"targets": [2, 3],
|
|
|
|
"searchable": false
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"scrollX": false,
|
|
|
|
"scrollY": false,
|
|
|
|
"responsive": true,
|
|
|
|
"language": {
|
|
|
|
"loadingRecords": "",
|
|
|
|
"emptyTable": "No files or folders"
|
|
|
|
},
|
|
|
|
"initComplete": function (settings, json) {
|
|
|
|
table.button().add(0, 'refresh');
|
2022-05-22 09:45:49 +00:00
|
|
|
//table.button().add(0, 'pageLength');
|
2022-02-06 15:46:43 +00:00
|
|
|
table.button().add(0, 'download');
|
2022-05-09 17:09:43 +00:00
|
|
|
{{if gt .Scope 1}}
|
|
|
|
table.button().add(0, 'addFiles');
|
|
|
|
{{end}}
|
2022-02-06 15:46:43 +00:00
|
|
|
table.buttons().container().appendTo('.col-md-6:eq(0)', table.table().container());
|
|
|
|
},
|
|
|
|
"orderFixed": [0, 'asc'],
|
|
|
|
"order": [1, 'asc']
|
|
|
|
});
|
|
|
|
|
|
|
|
new $.fn.dataTable.FixedHeader(table);
|
|
|
|
$.fn.dataTable.ext.errMode = 'none';
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
{{end}}
|