correctly report the relevant file size limit
...when a file exceeds the current user/teams's max size
This commit is contained in:
parent
3b7f5c2df7
commit
2dd6cf7b5c
1 changed files with 28 additions and 13 deletions
|
@ -33,6 +33,8 @@ define([
|
|||
sframeChan.query('Q_UPLOAD_FILE', data, cb);
|
||||
};
|
||||
|
||||
|
||||
Messages.upload_tooLargeBrief = "File exceeds the {0}MB limit for this drive";
|
||||
module.create = function (common, config) {
|
||||
var File = {};
|
||||
//var origin = common.getMetadataMgr().getPrivateData().origin;
|
||||
|
@ -42,6 +44,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
|
||||
|
@ -97,9 +114,7 @@ define([
|
|||
}
|
||||
if (data.complete && data.href && data.uid) {
|
||||
if (response.expected(data.uid)) {
|
||||
response.handle(data.uid, [data.href]);
|
||||
}
|
||||
return;
|
||||
response.handle(data.uid, [data.href]); } return;
|
||||
}
|
||||
if (typeof data.progress !== "undefined" && response.expected(data.uid)) {
|
||||
return void updateProgress(data.progress);
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue