Commit bc677046 by Bence Dányi

webui: fix ajax file upload

fixes #104
parent 43248016
...@@ -343,7 +343,7 @@ var cloud = (function(cloud) { ...@@ -343,7 +343,7 @@ var cloud = (function(cloud) {
/** /**
* Requests a new upload link from the store server * Requests a new upload link from the store server
*/ */
self.getUploadURL = function() { self.getUploadURL = function(f) {
uploadURLRequestInProgress = true; uploadURLRequestInProgress = true;
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
...@@ -353,6 +353,7 @@ var cloud = (function(cloud) { ...@@ -353,6 +353,7 @@ var cloud = (function(cloud) {
success: function(data) { success: function(data) {
self.uploadURL(data.url); self.uploadURL(data.url);
uploadURLRequestInProgress = false; uploadURLRequestInProgress = false;
if (typeof f == 'function') f();
} }
}) })
} }
...@@ -387,8 +388,19 @@ var cloud = (function(cloud) { ...@@ -387,8 +388,19 @@ var cloud = (function(cloud) {
* Uploads the specified file(s) * Uploads the specified file(s)
*/ */
var readfiles = cloud.delayUntil(function(file, next) { var readfiles = cloud.delayUntil(function(file, next) {
console.log('read', file, next) for (var i in self.files()) {
//1 GB file limit var f = self.files()[i];
if (file.name == f.originalName) {
if (!confirm('Van már ilyen fájl! ' + file.name)) {
return next();
}
}
}
if (file.name.indexOf('.') == -1 && file.size % 4096 == 0) {
if (!confirm('A "' + file.name + '" mappának tűnik. Mappák feltöltése a weboldalon keresztül nem támogatott. Ha ez mégis egy fájl, az OK gombra kattintva a rendszer megpróbálja azt feltölteni.')) {
return next();
}
}
if (file.size > 1024 * 1024 * 1024) { if (file.size > 1024 * 1024 * 1024) {
$('#upload-zone').hide(); $('#upload-zone').hide();
$('#upload-error').show(); $('#upload-error').show();
...@@ -407,18 +419,11 @@ var cloud = (function(cloud) { ...@@ -407,18 +419,11 @@ var cloud = (function(cloud) {
var start = new Date().getTime(); var start = new Date().getTime();
xhr.open('POST', self.uploadURL()); xhr.open('POST', self.uploadURL());
xhr.onload = xhr.onerror = function() { xhr.onload = xhr.onerror = function() {
console.log('onload');
self.uploadProgress('0%'); self.uploadProgress('0%');
self.uploadURL('/'); self.uploadURL('/');
if (next) { console.log('complete, next');
console.log('complete, next')
next(); next();
} else {
$('.file-upload').removeClass('opened');
$('.file-upload .details').slideUp(700);
$('#upload-zone').show();
$('#upload-progress-text').hide();
loadFolder(self.currentPath());
}
} }
if (tests.progress) { if (tests.progress) {
$('#upload-zone').hide(); $('#upload-zone').hide();
...@@ -466,22 +471,25 @@ var cloud = (function(cloud) { ...@@ -466,22 +471,25 @@ var cloud = (function(cloud) {
var files = e.dataTransfer.files; var files = e.dataTransfer.files;
console.log(files); console.log(files);
console.log(e.dataTransfer.files); console.log(e.dataTransfer.files);
var i = 1; var i = 0;
readfiles(e.dataTransfer.files[0], function() { (function next() {
console.log('next', i); if (i >= files.length) {
next = arguments.callee; $('.file-upload').removeClass('opened');
return function() { $('.file-upload .details').slideUp(700);
console.log('readnext', i, len); $('#upload-zone').show();
if (i >= len - 2) { $('#upload-progress-text').hide();
console.log('end', i, len); loadFolder(self.currentPath());
self.getUploadURL();
readfiles(files[i++], null);
return; return;
} }
self.getUploadURL(); console.log('reading file ' + i);
readfiles(files[i++], next()); if (self.uploadURL() == '/') {
self.getUploadURL(function() {
readfiles(files[i++], next);
});
} else {
readfiles(files[i++], next);
} }
}()); })();
return false; return false;
}); });
document.addEventListener('dragover', function(e) { document.addEventListener('dragover', function(e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment