support larger upload sizes for users with premium accounts
This commit is contained in:
parent
87ef2b0899
commit
59ad80d7f1
@ -1,4 +1,3 @@
|
|||||||
/*@flow*/
|
|
||||||
/*
|
/*
|
||||||
globals module
|
globals module
|
||||||
*/
|
*/
|
||||||
@ -251,6 +250,9 @@ module.exports = {
|
|||||||
*/
|
*/
|
||||||
maxUploadSize: 20 * 1024 * 1024,
|
maxUploadSize: 20 * 1024 * 1024,
|
||||||
|
|
||||||
|
// XXX
|
||||||
|
premiumUploadSize: 100 * 1024 * 1024,
|
||||||
|
|
||||||
/* =====================
|
/* =====================
|
||||||
* HARDWARE RELATED
|
* HARDWARE RELATED
|
||||||
* ===================== */
|
* ===================== */
|
||||||
|
|||||||
@ -12,9 +12,41 @@ Upload.status = function (Env, safeKey, filesize, _cb) { // FIXME FILES
|
|||||||
if (typeof(filesize) !== 'number' &&
|
if (typeof(filesize) !== 'number' &&
|
||||||
filesize >= 0) { return void cb('E_INVALID_SIZE'); }
|
filesize >= 0) { return void cb('E_INVALID_SIZE'); }
|
||||||
|
|
||||||
if (filesize >= Env.maxUploadSize) { return cb('TOO_LARGE'); }
|
|
||||||
|
|
||||||
nThen(function (w) {
|
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);
|
var abortAndCB = Util.both(w.abort, cb);
|
||||||
Env.blobStore.status(safeKey, w(function (err, inProgress) {
|
Env.blobStore.status(safeKey, w(function (err, inProgress) {
|
||||||
// if there's an error something is weird
|
// if there's an error something is weird
|
||||||
|
|||||||
@ -43,6 +43,7 @@ module.exports.create = function (config, cb) {
|
|||||||
//historyKeeper: config.historyKeeper,
|
//historyKeeper: config.historyKeeper,
|
||||||
intervals: config.intervals || {},
|
intervals: config.intervals || {},
|
||||||
maxUploadSize: config.maxUploadSize || (20 * 1024 * 1024),
|
maxUploadSize: config.maxUploadSize || (20 * 1024 * 1024),
|
||||||
|
premiumUploadSize: false, // overridden below...
|
||||||
Sessions: {},
|
Sessions: {},
|
||||||
paths: {},
|
paths: {},
|
||||||
//msgStore: config.store,
|
//msgStore: config.store,
|
||||||
@ -70,6 +71,13 @@ module.exports.create = function (config, cb) {
|
|||||||
domain: config.domain
|
domain: config.domain
|
||||||
};
|
};
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
var pes = config.premiumUploadSize;
|
||||||
|
if (!isNaN(pes) && pes >= Env.maxUploadSize) {
|
||||||
|
Env.premiumUploadSize = pes;
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
|
||||||
var paths = Env.paths;
|
var paths = Env.paths;
|
||||||
|
|
||||||
var keyOrDefaultString = function (key, def) {
|
var keyOrDefaultString = function (key, def) {
|
||||||
|
|||||||
@ -158,10 +158,15 @@ define([
|
|||||||
});
|
});
|
||||||
|
|
||||||
onError = function (e) {
|
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.inProgress = false;
|
||||||
queue.next();
|
queue.next();
|
||||||
if (e === 'TOO_LARGE') {
|
if (e === 'TOO_LARGE') {
|
||||||
$pv.text(Messages.upload_tooLargeBrief);
|
$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);
|
return void UI.alert(Messages.upload_tooLarge);
|
||||||
}
|
}
|
||||||
if (e === 'NOT_ENOUGH_SPACE') {
|
if (e === 'NOT_ENOUGH_SPACE') {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user