Added comments to upload and fixed a bug with unsupported files
This commit is contained in:
parent
2021f850c4
commit
b45112f4a8
@ -58,19 +58,52 @@ upload = {
|
|||||||
var albumID = album.getID(),
|
var albumID = album.getID(),
|
||||||
process = function(files, file) {
|
process = function(files, file) {
|
||||||
|
|
||||||
|
var formData = new FormData(),
|
||||||
|
xhr = new XMLHttpRequest(),
|
||||||
|
pre_progress = 0,
|
||||||
|
progress,
|
||||||
|
finish = function() {
|
||||||
|
|
||||||
|
window.onbeforeunload = null;
|
||||||
|
|
||||||
|
$("#upload_files").val("");
|
||||||
|
|
||||||
|
upload.close();
|
||||||
|
|
||||||
|
if (album.getID()===false) lychee.goto("0");
|
||||||
|
else album.load(albumID);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check if file is supported
|
||||||
if (file.supported===false) {
|
if (file.supported===false) {
|
||||||
|
|
||||||
// Skip file
|
// Skip file
|
||||||
if (file.next!==null) process(files, file.next);
|
if (file.next!==null) process(files, file.next);
|
||||||
|
else {
|
||||||
|
|
||||||
|
// Look for supported files
|
||||||
|
// If zero files are supported, hide the upload after a delay
|
||||||
|
|
||||||
|
var hasSupportedFiles = false;
|
||||||
|
|
||||||
|
for (var i = 0; i < files.length; i++) {
|
||||||
|
|
||||||
|
if (files[i].supported===true) {
|
||||||
|
hasSupportedFiles = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasSupportedFiles===false) setTimeout(finish, 2000);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var formData = new FormData(),
|
|
||||||
xhr = new XMLHttpRequest(),
|
|
||||||
pre_progress = 0,
|
|
||||||
progress;
|
|
||||||
|
|
||||||
formData.append("function", "upload");
|
formData.append("function", "upload");
|
||||||
formData.append("albumID", albumID);
|
formData.append("albumID", albumID);
|
||||||
formData.append(0, file);
|
formData.append(0, file);
|
||||||
@ -79,10 +112,12 @@ upload = {
|
|||||||
|
|
||||||
xhr.onload = function() {
|
xhr.onload = function() {
|
||||||
|
|
||||||
var wait;
|
// On success
|
||||||
|
|
||||||
if (xhr.status===200) {
|
if (xhr.status===200) {
|
||||||
|
|
||||||
|
var wait;
|
||||||
|
|
||||||
|
// Set status to finished
|
||||||
$(".upload_message .rows .row:nth-child(" + (file.num+1) + ") .status")
|
$(".upload_message .rows .row:nth-child(" + (file.num+1) + ") .status")
|
||||||
.html("Finished")
|
.html("Finished")
|
||||||
.addClass("success");
|
.addClass("success");
|
||||||
@ -90,6 +125,7 @@ upload = {
|
|||||||
file.ready = true;
|
file.ready = true;
|
||||||
wait = false;
|
wait = false;
|
||||||
|
|
||||||
|
// Check if there are file which are not finished
|
||||||
for (var i = 0; i < files.length; i++) {
|
for (var i = 0; i < files.length; i++) {
|
||||||
|
|
||||||
if (files[i].ready===false) {
|
if (files[i].ready===false) {
|
||||||
@ -99,18 +135,8 @@ upload = {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wait===false) {
|
// Finish upload when all files are finished
|
||||||
|
if (wait===false) finish();
|
||||||
window.onbeforeunload = null;
|
|
||||||
|
|
||||||
$("#upload_files").val("");
|
|
||||||
|
|
||||||
upload.close();
|
|
||||||
|
|
||||||
if (album.getID()===false) lychee.goto("0");
|
|
||||||
else album.load(albumID);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,8 +146,10 @@ upload = {
|
|||||||
|
|
||||||
if (e.lengthComputable) {
|
if (e.lengthComputable) {
|
||||||
|
|
||||||
|
// Calculate progress
|
||||||
progress = (e.loaded / e.total * 100 | 0);
|
progress = (e.loaded / e.total * 100 | 0);
|
||||||
|
|
||||||
|
// Set progress when progress has changed
|
||||||
if (progress>pre_progress) {
|
if (progress>pre_progress) {
|
||||||
$(".upload_message .rows .row:nth-child(" + (file.num+1) + ") .status").html(progress + "%");
|
$(".upload_message .rows .row:nth-child(" + (file.num+1) + ") .status").html(progress + "%");
|
||||||
pre_progress = progress;
|
pre_progress = progress;
|
||||||
@ -129,12 +157,15 @@ upload = {
|
|||||||
|
|
||||||
if (progress>=100) {
|
if (progress>=100) {
|
||||||
|
|
||||||
|
// Scroll to the uploading file
|
||||||
var scrollPos = 0;
|
var scrollPos = 0;
|
||||||
if ((file.num+1)>4) scrollPos = (file.num + 1 - 4) * 40
|
if ((file.num+1)>4) scrollPos = (file.num + 1 - 4) * 40
|
||||||
$(".upload_message .rows").scrollTop(scrollPos);
|
$(".upload_message .rows").scrollTop(scrollPos);
|
||||||
|
|
||||||
|
// Set status to processing
|
||||||
$(".upload_message .rows .row:nth-child(" + (file.num+1) + ") .status").html("Processing");
|
$(".upload_message .rows .row:nth-child(" + (file.num+1) + ") .status").html("Processing");
|
||||||
|
|
||||||
|
// Upload next file
|
||||||
if (file.next!==null) process(files, file.next);
|
if (file.next!==null) process(files, file.next);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -159,6 +190,7 @@ upload = {
|
|||||||
if (i < files.length-1) files[i].next = files[i+1];
|
if (i < files.length-1) files[i].next = files[i+1];
|
||||||
else files[i].next = null;
|
else files[i].next = null;
|
||||||
|
|
||||||
|
// Check if file is supported
|
||||||
if (files[i].type!=="image/jpeg"&&files[i].type!=="image/jpg"&&files[i].type!=="image/png"&&files[i].type!=="image/gif") {
|
if (files[i].type!=="image/jpeg"&&files[i].type!=="image/jpg"&&files[i].type!=="image/png"&&files[i].type!=="image/gif") {
|
||||||
|
|
||||||
files[i].ready = true;
|
files[i].ready = true;
|
||||||
@ -172,6 +204,7 @@ upload = {
|
|||||||
|
|
||||||
upload.show("Uploading", files);
|
upload.show("Uploading", files);
|
||||||
|
|
||||||
|
// Upload first file
|
||||||
process(files, files[0]);
|
process(files, files[0]);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user