Replace jimp with sharp (#6774)

* add probe image size and max image size

* replace jimp and image-probe with sharp

* better name for test

* resize with just path

* resize thumb inplace

* use filename
This commit is contained in:
Barış Soner Uşaklı
2018-09-20 17:05:52 -04:00
committed by GitHub
parent 69c7260fe9
commit b7ead6dc9c
16 changed files with 140 additions and 126 deletions

View File

@@ -15,6 +15,8 @@ var privileges = require('../src/privileges');
var meta = require('../src/meta');
var socketUser = require('../src/socket.io/user');
var helpers = require('./helpers');
var file = require('../src/file');
var image = require('../src/image');
describe('Upload Controllers', function () {
var tid;
@@ -133,6 +135,38 @@ describe('Upload Controllers', function () {
});
});
it('should fail to upload image to post if image dimensions are too big', function (done) {
helpers.uploadFile(nconf.get('url') + '/api/post/upload', path.join(__dirname, '../test/files/toobig.jpg'), {}, jar, csrf_token, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 500);
assert(body.error, '[[error:invalid-image-dimensions]]');
done();
});
});
it('should fail to upload image to post if image is broken', function (done) {
helpers.uploadFile(nconf.get('url') + '/api/post/upload', path.join(__dirname, '../test/files/brokenimage.png'), {}, jar, csrf_token, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 500);
assert(body.error, 'invalid block type');
done();
});
});
it('should fail if file is not an image', function (done) {
file.isFileTypeAllowed(path.join(__dirname, '../test/files/notanimage.png'), function (err) {
assert.equal(err.message, 'Input file is missing or of an unsupported image format');
done();
});
});
it('should fail if file is not an image', function (done) {
image.size(path.join(__dirname, '../test/files/notanimage.png'), function (err) {
assert.equal(err.message, 'Input file is missing or of an unsupported image format');
done();
});
});
it('should fail if topic thumbs are disabled', function (done) {
helpers.uploadFile(nconf.get('url') + '/api/topic/thumb/upload', path.join(__dirname, '../test/files/test.png'), {}, jar, csrf_token, function (err, res, body) {
assert.ifError(err);