upload files one by one

This commit is contained in:
j 2016-01-13 21:47:51 +05:30
parent fcc03c742d
commit cd949c4f20

View file

@ -1012,13 +1012,24 @@ oml.updateDebugMenu = function() {
};
oml.supportedExtensions = ['pdf', 'epub', 'cbr', 'cbz'];
oml.upload = function(files, callback) {
oml.upload = function(fileslist, callback) {
var files = [], ids = [];
for (var i = 0; i < fileslist.length; i++) {
var extension = Ox.last(fileslist[i].name.split('.'));
if (Ox.contains(oml.supportedExtensions, extension)) {
files.push(fileslist[i]);
}
}
Ox.serialForEach(files, function(file, index, array, next) {
var request = new XMLHttpRequest(),
url = '/api/upload/';
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (request.status == 200) {
callback(JSON.parse(request.responseText), null);
next();
var response = JSON.parse(request.responseText);
ids.concat(response.data.ids);
} else {
callback(null, {
code: request.status,
@ -1028,15 +1039,16 @@ oml.upload = function(files, callback) {
}
};
var formData = new FormData();
for (var i=0; i < files.length; i++) {
var extension = Ox.last(files[i].name.split('.'));
if (Ox.contains(oml.supportedExtensions, extension)) {
formData.append('files', files[i]);
}
}
formData.append('files', file);
if (oml.user.ui._list[0] == ':' && oml.user.ui._list.length > 1) {
formData.append('list', oml.user.ui._list.slice(1));
}
request.open('post', url, true);
request.send(formData);
}, function() {
callback({
'status': {'code': 200},
'data': {'ids': ids}
});
});
};