fix(avatars): add configuration to adjust avatar upload size

Closes #158
This commit is contained in:
Sean McArthur 2015-10-19 11:26:53 -07:00
Родитель 1fde0f2d5c
Коммит bc86f16887
6 изменённых файлов: 25 добавлений и 13 удалений

Просмотреть файл

@ -68,6 +68,10 @@ const conf = convict({
doc: 'Path or bucket name for images to be served publicly.',
default: 'BUCKET_NAME'
}
},
maxSize: {
doc: 'Maximum bytes allow for uploads',
default: 1024 * 1024 * 1 // 1MB
}
},
compute: {

Просмотреть файл

@ -35,7 +35,8 @@ module.exports = {
payload: {
output: 'stream',
parse: false,
allow: ['image/png', 'image/jpeg']
allow: ['image/png', 'image/jpeg'],
maxBytes: config.get('img.uploads.maxSize')
},
response: {
schema: {

Просмотреть файл

@ -45,7 +45,8 @@ exports.create = function() {
payload: {
output: 'stream',
parse: false,
allow: ['image/png', 'image/jpeg']
allow: ['image/png', 'image/jpeg'],
maxBytes: config.img.uploads.maxSize
},
handler: function upload(req, reply) {
logger.debug('worker.receive', {

Просмотреть файл

@ -458,7 +458,7 @@ describe('/avatar', function() {
email: 'user@example.domain',
scope: ['profile:avatar:write']
});
mock.image();
mock.image(imageData.length);
return Server.api.post({
url: '/avatar/upload',
payload: imageData,
@ -489,7 +489,7 @@ describe('/avatar', function() {
email: 'user@example.domain',
scope: ['profile:avatar:write']
});
mock.workerFailure('post');
mock.workerFailure('post', imageData.length);
mock.log('img_workers', function(rec) {
if (rec.levelname === 'ERROR') {
assert.equal(
@ -573,7 +573,7 @@ describe('/avatar', function() {
email: 'user@example.domain',
scope: ['profile:avatar:write']
});
mock.image();
mock.image(imageData.length);
return Server.api.post({
url: '/avatar/upload',
payload: imageData,

Просмотреть файл

@ -57,7 +57,7 @@ describe('events', function() {
email: 'user@example.domain',
scope: ['profile:avatar:write']
});
mock.image();
mock.image(imageData.length);
return Server.api.post({
url: '/avatar/upload',
payload: imageData,
@ -93,7 +93,7 @@ describe('events', function() {
});
it('should not delete message on error', function(done) {
mock.workerFailure('delete');
mock.workerFailure('delete', 0);
events.onData(new Message(function() {
assert(false, 'message.del() should not be called');
}));

Просмотреть файл

@ -37,12 +37,15 @@ module.exports = function mock(options) {
return scope;
}
function worker() {
function worker(bytes) {
if (bytes == null) {
throw new Error('Content-Length argument required');
}
var parts = url.parse(config.get('worker.url'));
var path = '';
var headers = {
'content-type': 'image/png',
'content-length': 12696
'content-length': bytes
};
return nock(parts.protocol + '//' + parts.host, {
reqheaders: headers
@ -134,14 +137,17 @@ module.exports = function mock(options) {
},
workerFailure: function workerFailure(action) {
workerFailure: function workerFailure(action, bytes) {
if (action !== 'post' && action !== 'delete') {
throw new Error('failure must be post or delete');
}
if (bytes == null) {
throw new Error('Content-Length argument required');
}
var parts = url.parse(config.get('worker.url'));
var headers = action === 'post' ? {
'content-type': 'image/png',
'content-length': 12696
'content-length': bytes
} : {};
return nock(parts.protocol + '//' + parts.host, {
reqheaders: headers
@ -152,8 +158,8 @@ module.exports = function mock(options) {
},
image: function image() {
worker();
image: function image(bytes) {
worker(bytes);
if (IS_AWS) {
uploadAws();
}