mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
add threshold for image resizing
This commit is contained in:
@@ -33,10 +33,11 @@
|
|||||||
"allowUserHomePage": 1,
|
"allowUserHomePage": 1,
|
||||||
"allowMultipleBadges": 0,
|
"allowMultipleBadges": 0,
|
||||||
"maximumFileSize": 2048,
|
"maximumFileSize": 2048,
|
||||||
"maximumImageWidth": 760,
|
"resizeImageWidthThreshold": 2000,
|
||||||
|
"resizeImageWidth": 760,
|
||||||
"rejectImageWidth": 5000,
|
"rejectImageWidth": 5000,
|
||||||
"rejectImageHeight": 5000,
|
"rejectImageHeight": 5000,
|
||||||
"resizeImageQuality": 60,
|
"resizeImageQuality": 80,
|
||||||
"topicThumbSize": 120,
|
"topicThumbSize": 120,
|
||||||
"minimumTitleLength": 3,
|
"minimumTitleLength": 3,
|
||||||
"maximumTitleLength": 255,
|
"maximumTitleLength": 255,
|
||||||
|
|||||||
@@ -4,8 +4,10 @@
|
|||||||
"private": "Make uploaded files private",
|
"private": "Make uploaded files private",
|
||||||
"private-extensions": "File extensions to make private",
|
"private-extensions": "File extensions to make private",
|
||||||
"private-uploads-extensions-help": "Enter comma-separated list of file extensions to make private here (e.g. <code>pdf,xls,doc</code>). An empty list means all files are private.",
|
"private-uploads-extensions-help": "Enter comma-separated list of file extensions to make private here (e.g. <code>pdf,xls,doc</code>). An empty list means all files are private.",
|
||||||
"max-image-width": "Resize images down to specified width (in pixels)",
|
"resize-image-width-threshold": "Resize images if they are wider than specified width",
|
||||||
"max-image-width-help": "(in pixels, default: 760 pixels, set to 0 to disable)",
|
"resize-image-width-threshold-help": "(in pixels, default: 1520 pixels, set to 0 to disable)",
|
||||||
|
"resize-image-width": "Resize images down to specified width",
|
||||||
|
"resize-image-width-help": "(in pixels, default: 760 pixels, set to 0 to disable)",
|
||||||
"resize-image-quality": "Quality to use when resizing images",
|
"resize-image-quality": "Quality to use when resizing images",
|
||||||
"resize-image-quality-help": "Use a lower quality setting to reduce the file size of resized images.",
|
"resize-image-quality-help": "Use a lower quality setting to reduce the file size of resized images.",
|
||||||
"max-file-size": "Maximum File Size (in KiB)",
|
"max-file-size": "Maximum File Size (in KiB)",
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ function uploadAsImage(req, uploadedFile, callback) {
|
|||||||
uploadsController.uploadFile(req.uid, uploadedFile, next);
|
uploadsController.uploadFile(req.uid, uploadedFile, next);
|
||||||
},
|
},
|
||||||
function (fileObj, next) {
|
function (fileObj, next) {
|
||||||
if (meta.config.maximumImageWidth === 0) {
|
if (meta.config.resizeImageWidth === 0 || meta.config.resizeImageWidthThreshold === 0) {
|
||||||
return next(null, fileObj);
|
return next(null, fileObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,14 +112,14 @@ function resizeImage(fileObj, callback) {
|
|||||||
image.size(fileObj.path, next);
|
image.size(fileObj.path, next);
|
||||||
},
|
},
|
||||||
function (imageData, next) {
|
function (imageData, next) {
|
||||||
if (imageData.width < meta.config.maximumImageWidth) {
|
if (imageData.width < meta.config.resizeImageWidthThreshold || meta.config.resizeImageWidth > meta.config.resizeImageWidthThreshold) {
|
||||||
return callback(null, fileObj);
|
return callback(null, fileObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
image.resizeImage({
|
image.resizeImage({
|
||||||
path: fileObj.path,
|
path: fileObj.path,
|
||||||
target: file.appendToFileName(fileObj.path, '-resized'),
|
target: file.appendToFileName(fileObj.path, '-resized'),
|
||||||
width: meta.config.maximumImageWidth,
|
width: meta.config.resizeImageWidth,
|
||||||
quality: meta.config.resizeImageQuality,
|
quality: meta.config.resizeImageQuality,
|
||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
|
|||||||
24
src/upgrades/1.11.0/resize_image_width.js
Normal file
24
src/upgrades/1.11.0/resize_image_width.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var db = require('../../database');
|
||||||
|
|
||||||
|
var async = require('async');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'Rename maximumImageWidth to resizeImageWidth',
|
||||||
|
timestamp: Date.UTC(2018, 9, 24),
|
||||||
|
method: function (callback) {
|
||||||
|
const meta = require('../../meta');
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
meta.configs.get('maximumImageWidth', next);
|
||||||
|
},
|
||||||
|
function (value, next) {
|
||||||
|
meta.configs.set('resizeImageWidth', value, next);
|
||||||
|
},
|
||||||
|
function (next) {
|
||||||
|
db.deleteObjectField('config', 'maximumImageWidth', next);
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -28,29 +28,29 @@
|
|||||||
<div class="col-sm-2 col-xs-12 settings-header">[[admin/settings/post:length]]</div>
|
<div class="col-sm-2 col-xs-12 settings-header">[[admin/settings/post:length]]</div>
|
||||||
<div class="col-sm-10 col-xs-12">
|
<div class="col-sm-10 col-xs-12">
|
||||||
<form>
|
<form>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-6">
|
<div class="col-xs-6">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="minimumTitleLength">[[admin/settings/post:restrictions.min-title-length]]</label>
|
<label for="minimumTitleLength">[[admin/settings/post:restrictions.min-title-length]]</label>
|
||||||
<input id="minimumTitleLength" type="text" class="form-control" value="3" data-field="minimumTitleLength">
|
<input id="minimumTitleLength" type="text" class="form-control" value="3" data-field="minimumTitleLength">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="maximumTitleLength">[[admin/settings/post:restrictions.max-title-length]]</label>
|
<label for="maximumTitleLength">[[admin/settings/post:restrictions.max-title-length]]</label>
|
||||||
<input id="maximumTitleLength" type="text" class="form-control" value="255" data-field="maximumTitleLength">
|
<input id="maximumTitleLength" type="text" class="form-control" value="255" data-field="maximumTitleLength">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-xs-6">
|
<div class="col-xs-6">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="minimumPostLength">[[admin/settings/post:restrictions.min-post-length]]</label>
|
<label for="minimumPostLength">[[admin/settings/post:restrictions.min-post-length]]</label>
|
||||||
<input id="minimumPostLength" type="text" class="form-control" value="8" data-field="minimumPostLength">
|
<input id="minimumPostLength" type="text" class="form-control" value="8" data-field="minimumPostLength">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="maximumPostLength">[[admin/settings/post:restrictions.max-post-length]]</label>
|
<label for="maximumPostLength">[[admin/settings/post:restrictions.max-post-length]]</label>
|
||||||
<input id="maximumPostLength" type="text" class="form-control" value="32767" data-field="maximumPostLength">
|
<input id="maximumPostLength" type="text" class="form-control" value="32767" data-field="maximumPostLength">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@
|
|||||||
<label for="preventTopicDeleteAfterReplies">[[admin/settings/post:restrictions.replies-no-delete]]</label>
|
<label for="preventTopicDeleteAfterReplies">[[admin/settings/post:restrictions.replies-no-delete]]</label>
|
||||||
<input id="preventTopicDeleteAfterReplies" type="text" class="form-control" value="0" data-field="preventTopicDeleteAfterReplies">
|
<input id="preventTopicDeleteAfterReplies" type="text" class="form-control" value="0" data-field="preventTopicDeleteAfterReplies">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="topicStaleDays">[[admin/settings/post:restrictions.days-until-stale]]</label>
|
<label for="topicStaleDays">[[admin/settings/post:restrictions.days-until-stale]]</label>
|
||||||
<input id="topicStaleDays" type="text" class="form-control" value="60" data-field="topicStaleDays">
|
<input id="topicStaleDays" type="text" class="form-control" value="60" data-field="topicStaleDays">
|
||||||
@@ -98,7 +98,7 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="initialPostDelay">[[admin/settings/post:restrictions.seconds-defore-new]]</label>
|
<label for="initialPostDelay">[[admin/settings/post:restrictions.seconds-defore-new]]</label>
|
||||||
<input id="initialPostDelay" type="text" class="form-control" value="10" data-field="initialPostDelay">
|
<input id="initialPostDelay" type="text" class="form-control" value="10" data-field="initialPostDelay">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -113,7 +113,7 @@
|
|||||||
[[admin/settings/post:restrictions.post-queue-help]]
|
[[admin/settings/post:restrictions.post-queue-help]]
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="newbiePostDelayThreshold">[[admin/settings/post:restrictions.rep-threshold]]</label>
|
<label for="newbiePostDelayThreshold">[[admin/settings/post:restrictions.rep-threshold]]</label>
|
||||||
<input id="newbiePostDelayThreshold" type="text" class="form-control" value="3" data-field="newbiePostDelayThreshold">
|
<input id="newbiePostDelayThreshold" type="text" class="form-control" value="3" data-field="newbiePostDelayThreshold">
|
||||||
|
|||||||
@@ -28,12 +28,26 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="row">
|
||||||
<label for="maximumImageWidth">[[admin/settings/uploads:max-image-width]]</label>
|
<div class="col-xs-6">
|
||||||
<input type="text" class="form-control" value="760" data-field="maximumImageWidth" placeholder="760">
|
<div class="form-group">
|
||||||
<p class="help-block">
|
<label for="resizeImageWidthThreshold">[[admin/settings/uploads:resize-image-width-threshold]]</label>
|
||||||
[[admin/settings/uploads:max-image-width-help]]
|
<input type="text" class="form-control" value="2000" data-field="resizeImageWidthThreshold" placeholder="2000">
|
||||||
</p>
|
<p class="help-block">
|
||||||
|
[[admin/settings/uploads:resize-image-width-threshold-help]]
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-xs-6">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="resizeImageWidth">[[admin/settings/uploads:resize-image-width]]</label>
|
||||||
|
<input type="text" class="form-control" value="760" data-field="resizeImageWidth" placeholder="760">
|
||||||
|
<p class="help-block">
|
||||||
|
[[admin/settings/uploads:resize-image-width-help]]
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@@ -89,6 +103,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|||||||
@@ -108,15 +108,17 @@ describe('Upload Controllers', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should resize and upload an image to a post', function (done) {
|
it('should resize and upload an image to a post', function (done) {
|
||||||
var oldValue = meta.config.maximumImageWidth;
|
var oldValue = meta.config.resizeImageWidth;
|
||||||
meta.config.maximumImageWidth = 10;
|
meta.config.resizeImageWidth = 10;
|
||||||
|
meta.config.resizeImageWidthThreshold = 10;
|
||||||
helpers.uploadFile(nconf.get('url') + '/api/post/upload', path.join(__dirname, '../test/files/test.png'), {}, jar, csrf_token, function (err, res, body) {
|
helpers.uploadFile(nconf.get('url') + '/api/post/upload', path.join(__dirname, '../test/files/test.png'), {}, jar, csrf_token, function (err, res, body) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(res.statusCode, 200);
|
assert.equal(res.statusCode, 200);
|
||||||
assert(Array.isArray(body));
|
assert(Array.isArray(body));
|
||||||
assert(body[0].url);
|
assert(body[0].url);
|
||||||
assert(body[0].url.match(/\/assets\/uploads\/files\/\d+-test-resized\.png/));
|
assert(body[0].url.match(/\/assets\/uploads\/files\/\d+-test-resized\.png/));
|
||||||
meta.config.maximumImageWidth = oldValue;
|
meta.config.resizeImageWidth = oldValue;
|
||||||
|
meta.config.resizeImageWidthThreshold = 1520;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user