|
|
|
@ -42,6 +42,21 @@ define([
|
|
|
|
|
|
|
|
|
|
var teamId = config.teamId;
|
|
|
|
|
|
|
|
|
|
var getFormattedUploadLimit = function (cb) {
|
|
|
|
|
common.getPinUsage(teamId, (err, data) => {
|
|
|
|
|
// sensible default?
|
|
|
|
|
if (err || !data) {
|
|
|
|
|
return void cb(void 0, ApiConfig.maxUploadSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var lesser = ApiConfig.maxUploadSize;
|
|
|
|
|
var greater = ApiConfig.premiumUploadSize || lesser;
|
|
|
|
|
if (data.plan) { return void cb(void 0, Util.bytesToMegabytes(greater)); }
|
|
|
|
|
|
|
|
|
|
cb(void 0, Util.bytesToMegabytes(lesser));
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var queue = File.queue = {
|
|
|
|
|
queue: [],
|
|
|
|
|
inProgress: false
|
|
|
|
@ -127,20 +142,20 @@ define([
|
|
|
|
|
var $pb = $row.find('.cp-fileupload-table-progressbar');
|
|
|
|
|
var $link = $row.find('.cp-fileupload-table-link');
|
|
|
|
|
|
|
|
|
|
var privateData = common.getMetadataMgr().getPrivateData();
|
|
|
|
|
var l = privateData.plan ? ApiConfig.premiumUploadSize : false;
|
|
|
|
|
l = l || ApiConfig.maxUploadSize || "?";
|
|
|
|
|
var maxSizeStr = Util.bytesToMegabytes(l);
|
|
|
|
|
var limit = ApiConfig.premiumUploadSize || ApiConfig.maxUploadSize;
|
|
|
|
|
|
|
|
|
|
var estimate = FileCrypto.computeEncryptedSize((blob && blob.byteLength) || 0, metadata);
|
|
|
|
|
if (blob && blob.byteLength && typeof(estimate) === 'number' && typeof(l) === "number" && estimate > l) {
|
|
|
|
|
if (blob && blob.byteLength && typeof(estimate) === 'number' && typeof(limit) === "number" && estimate > limit) {
|
|
|
|
|
$pv.text(Messages.error);
|
|
|
|
|
queue.inProgress = false;
|
|
|
|
|
queue.next();
|
|
|
|
|
if (config.onError) { config.onError("TOO_LARGE"); }
|
|
|
|
|
return void UI.alert(Messages._getKey('upload_tooLargeBrief', [maxSizeStr]));
|
|
|
|
|
// If the file is too large then we need to know what the relevant limit is
|
|
|
|
|
return void getFormattedUploadLimit((err, maxSizeStr) => {
|
|
|
|
|
UI.alert(Messages._getKey('upload_tooLargeBrief', [maxSizeStr]));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update progress in the download panel, for uploading a file
|
|
|
|
|
* @param {number} progressValue Progression of download, between 0 and 100
|
|
|
|
@ -176,8 +191,6 @@ define([
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
onError = function (e) {
|
|
|
|
|
// TODO if we included the max upload sizes in /api/config
|
|
|
|
|
// then we could check if a file is too large without going to the server...
|
|
|
|
|
queue.inProgress = false;
|
|
|
|
|
queue.next();
|
|
|
|
|
|
|
|
|
@ -185,7 +198,9 @@ define([
|
|
|
|
|
|
|
|
|
|
if (e === 'TOO_LARGE') {
|
|
|
|
|
$pv.text(Messages.error);
|
|
|
|
|
return void UI.alert(Messages._getKey('upload_tooLargeBrief', [maxSizeStr]));
|
|
|
|
|
return void getFormattedUploadLimit((err, maxSizeStr) => {
|
|
|
|
|
UI.alert(Messages._getKey('upload_tooLargeBrief', [maxSizeStr]));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (e === 'NOT_ENOUGH_SPACE') {
|
|
|
|
|
$pv.text(Messages.upload_notEnoughSpaceBrief);
|
|
|
|
|