mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-11 21:31:52 +02:00
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:
committed by
GitHub
parent
69c7260fe9
commit
b7ead6dc9c
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user