2022-07-17 18:16:00 +00:00
|
|
|
<!--
|
2023-11-04 09:54:52 +00:00
|
|
|
Copyright (C) 2023 Nicola Murino
|
2022-07-17 18:16:00 +00:00
|
|
|
|
2023-11-04 09:54:52 +00:00
|
|
|
This WebUI uses the KeenThemes Mega Bundle, a proprietary theme:
|
2022-07-17 18:16:00 +00:00
|
|
|
|
2023-11-04 09:54:52 +00:00
|
|
|
https://keenthemes.com/products/templates-mega-bundle
|
2022-07-17 18:16:00 +00:00
|
|
|
|
2023-11-04 09:54:52 +00:00
|
|
|
KeenThemes HTML/CSS/JS components are allowed for use only within the
|
|
|
|
SFTPGo product and restricted to be used in a resealable HTML template
|
|
|
|
that can compete with KeenThemes products anyhow.
|
|
|
|
|
|
|
|
This WebUI is allowed for use only within the SFTPGo product and
|
|
|
|
therefore cannot be used in derivative works/products without an
|
|
|
|
explicit grant from the SFTPGo Team (support@sftpgo.com).
|
2022-07-17 18:16:00 +00:00
|
|
|
-->
|
2023-11-04 09:54:52 +00:00
|
|
|
{{- template "base" .}}
|
|
|
|
|
|
|
|
{{- define "page_body"}}
|
|
|
|
<div class="d-flex flex-center flex-column flex-column-fluid p-10 pb-lg-20">
|
|
|
|
<div class="mb-12">
|
|
|
|
<span>
|
|
|
|
<img alt="Logo" src="{{.StaticURL}}{{.Branding.LogoPath}}" class="h-80px" />
|
|
|
|
</span>
|
|
|
|
<span class="text-gray-800 fs-2 fw-semibold ps-5">
|
|
|
|
{{.Branding.ShortName}}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div class="card shadow-sm w-lg-600px">
|
|
|
|
<div class="card-header bg-light">
|
2023-12-26 07:59:52 +00:00
|
|
|
<h3 data-i18n="title.upload_to_share" class="card-title section-title">Upload one or more files to share</h3>
|
2023-11-04 09:54:52 +00:00
|
|
|
</div>
|
|
|
|
<div class="card-body">
|
|
|
|
{{- template "errmsg" ""}}
|
|
|
|
<form id="upload_files_form" action="{{.UploadBasePath}}" method="POST" enctype="multipart/form-data">
|
|
|
|
<div class="fv-row">
|
2024-03-31 18:42:28 +00:00
|
|
|
<div class="dropzone mh-350px overflow-auto visibility-auto" id="upload_files">
|
2023-11-04 09:54:52 +00:00
|
|
|
<div class="dz-message needsclick align-items-center">
|
|
|
|
<i class="ki-duotone ki-file-up fs-3x text-primary"><span class="path1"></span><span class="path2"></span></i>
|
|
|
|
<div class="ms-4">
|
2023-12-10 15:40:13 +00:00
|
|
|
<h3 data-i18n="fs.upload.message" class="fs-5 fw-bold text-gray-900 mb-1">Drop files here or click to upload.</h3>
|
2023-11-04 09:54:52 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-02-15 18:19:25 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-11-04 09:54:52 +00:00
|
|
|
<div class="d-flex justify-content-end mt-10">
|
2023-12-10 15:40:13 +00:00
|
|
|
<button data-i18n="general.submit" type="button" id="upload_files_button" class="btn btn-primary">Submit</button>
|
2023-11-04 09:54:52 +00:00
|
|
|
</div>
|
|
|
|
</form>
|
2022-02-15 18:19:25 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-11-04 09:54:52 +00:00
|
|
|
{{- end}}
|
2022-02-15 18:19:25 +00:00
|
|
|
|
2023-11-04 09:54:52 +00:00
|
|
|
{{- define "extra_js"}}
|
2023-11-16 17:55:14 +00:00
|
|
|
<script type="text/javascript" {{- if .CSPNonce}} nonce="{{.CSPNonce}}"{{- end}}>
|
2022-02-15 18:19:25 +00:00
|
|
|
|
2023-11-04 09:54:52 +00:00
|
|
|
function uploadFiles(files) {
|
|
|
|
let has_errors = false;
|
|
|
|
let index = 0;
|
|
|
|
let success = 0;
|
2024-03-31 18:42:28 +00:00
|
|
|
let checkedDirs = [];
|
2023-11-04 09:54:52 +00:00
|
|
|
$('#errorMsg').addClass("d-none");
|
2024-10-03 18:31:46 +00:00
|
|
|
clearLoading();
|
2023-11-04 09:54:52 +00:00
|
|
|
KTApp.showPageLoading();
|
2022-02-15 18:19:25 +00:00
|
|
|
|
2023-11-04 09:54:52 +00:00
|
|
|
function uploadFile() {
|
|
|
|
if (index >= files.length || has_errors) {
|
|
|
|
KTApp.hidePageLoading();
|
|
|
|
if (!has_errors) {
|
|
|
|
ModalAlert.fire({
|
2023-12-10 15:40:13 +00:00
|
|
|
text: $.t('fs.upload.success'),
|
2023-11-04 09:54:52 +00:00
|
|
|
icon: "success",
|
2023-12-10 15:40:13 +00:00
|
|
|
confirmButtonText: $.t('general.ok'),
|
2023-11-04 09:54:52 +00:00
|
|
|
customClass: {
|
|
|
|
confirmButton: 'btn btn-primary'
|
|
|
|
}
|
|
|
|
}).then((result) => {
|
|
|
|
if (result.isConfirmed){
|
|
|
|
location.reload();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return;
|
2022-02-15 18:19:25 +00:00
|
|
|
}
|
|
|
|
|
2023-11-04 09:54:52 +00:00
|
|
|
let f = files[index];
|
2024-03-31 18:42:28 +00:00
|
|
|
let name = f.name;
|
|
|
|
let mkdirParents = "false";
|
|
|
|
if (f.fullPath){
|
|
|
|
name = f.fullPath;
|
|
|
|
let dirName = name.substr(0, name.lastIndexOf("/"));
|
|
|
|
if (!checkedDirs.includes(dirName)){
|
|
|
|
mkdirParents = "true";
|
|
|
|
checkedDirs.push(dirName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let uploadPath = '{{.UploadBasePath}}/'+encodeURIComponent(name)+"?mkdir_parents="+mkdirParents;
|
2023-11-04 09:54:52 +00:00
|
|
|
let lastModified;
|
|
|
|
try {
|
|
|
|
lastModified = f.lastModified;
|
|
|
|
} catch (e) {
|
2023-12-10 15:40:13 +00:00
|
|
|
console.error("unable to get last modified time from file: " + e.message);
|
2023-11-04 09:54:52 +00:00
|
|
|
lastModified = "";
|
|
|
|
}
|
|
|
|
|
2024-10-03 18:31:46 +00:00
|
|
|
let info = "";
|
2023-11-04 09:54:52 +00:00
|
|
|
if (files.length > 1){
|
2024-10-03 18:31:46 +00:00
|
|
|
info = $.t('fs.uploading', {
|
2023-12-10 15:40:13 +00:00
|
|
|
idx: index + 1,
|
2024-10-03 18:31:46 +00:00
|
|
|
total: files.length
|
2023-12-10 15:40:13 +00:00
|
|
|
});
|
2023-11-04 09:54:52 +00:00
|
|
|
}
|
|
|
|
|
2024-10-03 18:31:46 +00:00
|
|
|
setLoadingText(info,f.name);
|
2023-11-04 09:54:52 +00:00
|
|
|
|
|
|
|
axios.post(uploadPath, f, {
|
|
|
|
headers: {
|
|
|
|
'X-SFTPGO-MTIME': lastModified,
|
|
|
|
'X-CSRF-TOKEN': '{{.CSRFToken}}'
|
|
|
|
},
|
|
|
|
onUploadProgress: function (progressEvent) {
|
|
|
|
if (!progressEvent.total){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const percentage = Math.round((100 * progressEvent.loaded) / progressEvent.total);
|
|
|
|
if (percentage > 0 && percentage < 100){
|
2024-10-03 18:31:46 +00:00
|
|
|
setLoadingText(info,`${f.name} ${percentage}%`);
|
2022-02-15 18:19:25 +00:00
|
|
|
}
|
2023-11-04 09:54:52 +00:00
|
|
|
},
|
|
|
|
validateStatus: function (status) {
|
|
|
|
return status == 201;
|
2022-02-15 18:19:25 +00:00
|
|
|
}
|
2023-11-04 09:54:52 +00:00
|
|
|
}).then(function (response) {
|
|
|
|
index++;
|
|
|
|
success++;
|
|
|
|
uploadFile();
|
|
|
|
}).catch(function (error) {
|
2023-12-10 15:40:13 +00:00
|
|
|
let errorMessage;
|
2023-11-04 09:54:52 +00:00
|
|
|
if (error && error.response) {
|
2023-12-10 15:40:13 +00:00
|
|
|
switch (error.response.status) {
|
|
|
|
case 403:
|
|
|
|
errorMessage = "fs.upload.err_403";
|
|
|
|
break;
|
|
|
|
case 429:
|
|
|
|
errorMessage = "fs.upload.err_429";
|
|
|
|
break;
|
2022-02-15 18:19:25 +00:00
|
|
|
}
|
|
|
|
}
|
2023-12-10 15:40:13 +00:00
|
|
|
if (!errorMessage){
|
|
|
|
errorMessage = "fs.upload.err_generic";
|
|
|
|
}
|
2023-11-04 09:54:52 +00:00
|
|
|
index++;
|
|
|
|
has_errors = true;
|
2023-12-10 15:40:13 +00:00
|
|
|
setI18NData($('#errorTxt'), errorMessage);
|
2023-11-04 09:54:52 +00:00
|
|
|
$('#errorMsg').removeClass("d-none");
|
|
|
|
uploadFile();
|
|
|
|
});
|
|
|
|
}
|
2022-02-15 18:19:25 +00:00
|
|
|
|
2023-11-04 09:54:52 +00:00
|
|
|
uploadFile();
|
|
|
|
}
|
|
|
|
|
|
|
|
KTUtil.onDOMContentLoaded(function () {
|
2024-10-03 17:06:33 +00:00
|
|
|
var lastAddedFile = Date.now();
|
|
|
|
|
|
|
|
function canUpload() {
|
|
|
|
// Ugly hack to detect if we are still loading a large file list when the user try to upload files.
|
|
|
|
// The Dropzone addedfiles event is fired for directories before the files within them are added to the queue.
|
|
|
|
// TODO: investigate if there is a better way.
|
|
|
|
if (Date.now() - lastAddedFile < 500) {
|
|
|
|
ModalAlert.fire({
|
|
|
|
text: $.t('fs.upload_queue_not_ready'),
|
|
|
|
icon: "warning",
|
|
|
|
confirmButtonText: $.t('general.ok'),
|
|
|
|
customClass: {
|
|
|
|
confirmButton: "btn btn-primary"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-11-04 09:54:52 +00:00
|
|
|
var dropzone = new Dropzone("#upload_files", {
|
|
|
|
url: "{{.UploadBasePath}}",
|
|
|
|
paramName: "filenames",
|
2024-03-31 18:42:28 +00:00
|
|
|
createImageThumbnails: false,
|
|
|
|
maxFiles: null,
|
2023-11-04 09:54:52 +00:00
|
|
|
maxFilesize: null,
|
|
|
|
autoQueue: false,
|
2024-03-31 18:42:28 +00:00
|
|
|
addRemoveLinks: false,
|
2023-11-04 09:54:52 +00:00
|
|
|
autoProcessQueue: false,
|
|
|
|
filesizeBase: 1000,
|
2024-03-31 18:42:28 +00:00
|
|
|
previewTemplate: `<div class="d-flex align-items-center mb-2">
|
|
|
|
<span class="bullet bullet-dot bg-primary me-2"></span>
|
|
|
|
<div class="text-break text-wrap text-left"><span class="fs-5 fw-semibold" data-dz-name></span> (<span class="fs-5 fw-semibold" data-custom-size></span>)</div>
|
|
|
|
</div>
|
|
|
|
<div class="dz-error-message d-none" data-dz-errormessage></div>
|
|
|
|
<div class="dz-progress d-none"><span class="dz-upload" data-dz-uploadprogress></span></div>
|
|
|
|
`,
|
2023-11-04 09:54:52 +00:00
|
|
|
init: function() {
|
|
|
|
var dropzone = this;
|
|
|
|
$("#upload_files_button").click(function(){
|
2024-10-03 17:06:33 +00:00
|
|
|
if (canUpload()){
|
|
|
|
uploadFiles(dropzone.getAcceptedFiles());
|
|
|
|
}
|
2022-02-15 18:19:25 +00:00
|
|
|
});
|
|
|
|
}
|
2023-11-04 09:54:52 +00:00
|
|
|
});
|
2022-02-15 18:19:25 +00:00
|
|
|
|
2023-11-04 09:54:52 +00:00
|
|
|
dropzone.on("addedfile", file => {
|
2024-03-31 18:42:28 +00:00
|
|
|
for (node of file.previewElement.querySelectorAll("[data-custom-size]")) {
|
|
|
|
node.textContent = fileSizeIEC(file.size);
|
|
|
|
}
|
|
|
|
if (file.fullPath){
|
|
|
|
for (var node of file.previewElement.querySelectorAll("[data-dz-name]")) {
|
|
|
|
node.textContent = file.fullPath;
|
|
|
|
}
|
|
|
|
}
|
2024-10-03 17:06:33 +00:00
|
|
|
lastAddedFile = Date.now();
|
2022-02-15 18:19:25 +00:00
|
|
|
});
|
|
|
|
});
|
2023-11-04 09:54:52 +00:00
|
|
|
|
2022-02-15 18:19:25 +00:00
|
|
|
</script>
|
2023-11-04 09:54:52 +00:00
|
|
|
{{- end}}
|