Handle case files array to unzip is empty

This commit is contained in:
Aurélien Georget 2015-11-20 14:22:46 +01:00
parent 5e92ba1068
commit 754abd3a5c

View File

@ -151,63 +151,74 @@ module.exports = function (strapi) {
return deferred.promise;
};
syncPromise(_.first(data.files), 0)
.then(function () {
if (data.hasOwnProperty('action') && _.isFunction(_self[data.action])) {
_self[data.action](data, function (err, obj) {
if (_.isEmpty(data.files)) {
fn({
appId: strapi.config.studio.appId,
token: strapi.token,
encrypted: strapi.rsa.encrypt({
err: null,
data: stringify({}, null, 2)
})
});
} else {
syncPromise(_.first(data.files), 0)
.then(function () {
if (data.hasOwnProperty('action') && _.isFunction(_self[data.action])) {
_self[data.action](data, function (err, obj) {
if (err) {
fn({
appId: strapi.config.studio.appId,
token: strapi.token,
encrypted: strapi.rsa.encrypt({
err: stringify(err, null, 2),
data: null
})
});
return false;
}
if (err) {
fn({
appId: strapi.config.studio.appId,
token: strapi.token,
encrypted: strapi.rsa.encrypt({
err: stringify(err, null, 2),
data: null
err: null,
data: stringify(obj, null, 2)
})
});
return false;
}
});
} else if (!data.hasOwnProperty('action')) {
fn({
appId: strapi.config.studio.appId,
token: strapi.token,
encrypted: strapi.rsa.encrypt({
err: null,
data: stringify(obj, null, 2)
data: stringify(true, null, 2)
})
});
});
} else if (!data.hasOwnProperty('action')) {
} else {
fn({
appId: strapi.config.studio.appId,
token: strapi.token,
encrypted: strapi.rsa.encrypt({
err: stringify('Unknow action', null, 2),
data: null
})
});
}
})
.catch(function (err) {
fn({
appId: strapi.config.studio.appId,
token: strapi.token,
encrypted: strapi.rsa.encrypt({
err: null,
data: stringify(true, null, 2)
})
});
} else {
fn({
appId: strapi.config.studio.appId,
token: strapi.token,
encrypted: strapi.rsa.encrypt({
err: stringify('Unknow action', null, 2),
err: err,
data: null
})
});
}
})
.catch(function (err) {
fn({
appId: strapi.config.studio.appId,
token: strapi.token,
encrypted: strapi.rsa.encrypt({
err: err,
data: null
})
});
});
}
} else if (!data.hasOwnProperty('action')) {
fn(strapi.rsa.encrypt(stringify('`action` attribute is missing', null, 2)), strapi.rsa.encryptPrivate(null));
} else if (_.isFunction(_self[data.action])) {