correctly report the relevant file size limit

...when a file exceeds the current user/teams's max size
master
ansuz 3 years ago
parent 3b7f5c2df7
commit 2dd6cf7b5c

@ -33,6 +33,8 @@ define([
sframeChan.query('Q_UPLOAD_FILE', data, cb); sframeChan.query('Q_UPLOAD_FILE', data, cb);
}; };
Messages.upload_tooLargeBrief = "File exceeds the {0}MB limit for this drive";
module.create = function (common, config) { module.create = function (common, config) {
var File = {}; var File = {};
//var origin = common.getMetadataMgr().getPrivateData().origin; //var origin = common.getMetadataMgr().getPrivateData().origin;
@ -42,6 +44,21 @@ define([
var teamId = config.teamId; 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 = { var queue = File.queue = {
queue: [], queue: [],
inProgress: false inProgress: false
@ -97,9 +114,7 @@ define([
} }
if (data.complete && data.href && data.uid) { if (data.complete && data.href && data.uid) {
if (response.expected(data.uid)) { if (response.expected(data.uid)) {
response.handle(data.uid, [data.href]); response.handle(data.uid, [data.href]); } return;
}
return;
} }
if (typeof data.progress !== "undefined" && response.expected(data.uid)) { if (typeof data.progress !== "undefined" && response.expected(data.uid)) {
return void updateProgress(data.progress); return void updateProgress(data.progress);
@ -127,20 +142,20 @@ define([
var $pb = $row.find('.cp-fileupload-table-progressbar'); var $pb = $row.find('.cp-fileupload-table-progressbar');
var $link = $row.find('.cp-fileupload-table-link'); var $link = $row.find('.cp-fileupload-table-link');
var privateData = common.getMetadataMgr().getPrivateData(); var limit = ApiConfig.premiumUploadSize || ApiConfig.maxUploadSize;
var l = privateData.plan ? ApiConfig.premiumUploadSize : false;
l = l || ApiConfig.maxUploadSize || "?";
var maxSizeStr = Util.bytesToMegabytes(l);
var estimate = FileCrypto.computeEncryptedSize((blob && blob.byteLength) || 0, metadata); 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); $pv.text(Messages.error);
queue.inProgress = false; queue.inProgress = false;
queue.next(); queue.next();
if (config.onError) { config.onError("TOO_LARGE"); } 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 * Update progress in the download panel, for uploading a file
* @param {number} progressValue Progression of download, between 0 and 100 * @param {number} progressValue Progression of download, between 0 and 100
@ -176,8 +191,6 @@ define([
}); });
onError = function (e) { 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.inProgress = false;
queue.next(); queue.next();
@ -185,7 +198,9 @@ define([
if (e === 'TOO_LARGE') { if (e === 'TOO_LARGE') {
$pv.text(Messages.error); $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') { if (e === 'NOT_ENOUGH_SPACE') {
$pv.text(Messages.upload_notEnoughSpaceBrief); $pv.text(Messages.upload_notEnoughSpaceBrief);

Loading…
Cancel
Save