diff --git a/config/config.example.js b/config/config.example.js index 90e96a66a..25a4c97a6 100644 --- a/config/config.example.js +++ b/config/config.example.js @@ -1,4 +1,3 @@ -/*@flow*/ /* globals module */ @@ -251,6 +250,9 @@ module.exports = { */ maxUploadSize: 20 * 1024 * 1024, + // XXX + premiumUploadSize: 100 * 1024 * 1024, + /* ===================== * HARDWARE RELATED * ===================== */ diff --git a/lib/commands/upload.js b/lib/commands/upload.js index 66868a65d..c64368949 100644 --- a/lib/commands/upload.js +++ b/lib/commands/upload.js @@ -12,9 +12,41 @@ Upload.status = function (Env, safeKey, filesize, _cb) { // FIXME FILES if (typeof(filesize) !== 'number' && filesize >= 0) { return void cb('E_INVALID_SIZE'); } - if (filesize >= Env.maxUploadSize) { return cb('TOO_LARGE'); } - nThen(function (w) { + // if the proposed upload size is within the regular limit + // jump ahead to the next block + if (filesize <= Env.maxUploadSize) { return; } + + // if larger uploads aren't explicitly enabled then reject them + if (typeof(Env.premiumUploadSize) !== 'number') { + w.abort(); + return void cb('TOO_LARGE'); + } + + // otherwise go and retrieve info about the user's quota + Pinning.getLimit(Env, safeKey, w(function (err, limit) { + if (err) { + w.abort(); + return void cb("E_BAD_LIMIT"); + } + + var plan = limit[1]; + + // see if they have a special plan, reject them if not + if (plan === '') { + w.abort(); + return void cb('TOO_LARGE'); + } + + // and that they're not over the greater limit + if (filesize >= Env.premiumUploadSize) { + w.abort(); + return void cb("TOO_LARGE"); + } + + // fallthrough will proceed to the next block + })); + }).nThen(function (w) { var abortAndCB = Util.both(w.abort, cb); Env.blobStore.status(safeKey, w(function (err, inProgress) { // if there's an error something is weird diff --git a/lib/historyKeeper.js b/lib/historyKeeper.js index 19e2e7b6f..45668a1b6 100644 --- a/lib/historyKeeper.js +++ b/lib/historyKeeper.js @@ -43,6 +43,7 @@ module.exports.create = function (config, cb) { //historyKeeper: config.historyKeeper, intervals: config.intervals || {}, maxUploadSize: config.maxUploadSize || (20 * 1024 * 1024), + premiumUploadSize: false, // overridden below... Sessions: {}, paths: {}, //msgStore: config.store, @@ -70,6 +71,13 @@ module.exports.create = function (config, cb) { domain: config.domain }; + (function () { + var pes = config.premiumUploadSize; + if (!isNaN(pes) && pes >= Env.maxUploadSize) { + Env.premiumUploadSize = pes; + } + }()); + var paths = Env.paths; var keyOrDefaultString = function (key, def) { diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index 2e2f47af0..1398e960b 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -158,10 +158,15 @@ define([ }); onError = function (e) { + // XXX 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(); if (e === 'TOO_LARGE') { $pv.text(Messages.upload_tooLargeBrief); + // XXX translate + // instead of "This file exceeds the maximum upload size" + // use "the maximum upload size allowed for your account" return void UI.alert(Messages.upload_tooLarge); } if (e === 'NOT_ENOUGH_SPACE') {