Skip to content

Commit

Permalink
🎨 Blog icon improvements (#8260)
Browse files Browse the repository at this point in the history
refs #7688

- blog icon error message
- change default favicon to 60px
  • Loading branch information
aileen authored and kirrg001 committed Apr 11, 2017
1 parent 06fc5f4 commit d9d182f
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 15 deletions.
14 changes: 7 additions & 7 deletions core/server/middleware/validation/blog-icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = function blogIcon() {

// CASE: file should not be larger than 100kb
if (!validIconSize(req.file.size)) {
return next(new errors.RequestEntityTooLargeError({message: i18n.t('errors.api.icons.fileSizeTooLarge', {extensions: iconExtensions})}));
return next(new errors.ValidationError({message: i18n.t('errors.api.icons.invalidFile', {extensions: iconExtensions})}));
}

return getIconDimensions(req.file).then(function (dimensions) {
Expand All @@ -70,18 +70,18 @@ module.exports = function blogIcon() {

// CASE: file needs to be a square
if (req.file.dimensions.width !== req.file.dimensions.height) {
return next(new errors.ValidationError({message: i18n.t('errors.api.icons.iconNotSquare', {extensions: iconExtensions})}));
return next(new errors.ValidationError({message: i18n.t('errors.api.icons.invalidFile', {extensions: iconExtensions})}));
}

// CASE: icon needs to be bigger than 32px
// .ico files can contain multiple sizes, we need at least a minimum of 32px (16px is ok, as long as 32px are present as well)
if (req.file.dimensions.width < 32) {
return next(new errors.ValidationError({message: i18n.t('errors.api.icons.fileTooSmall', {extensions: iconExtensions})}));
// CASE: icon needs to be bigger than 60px
// .ico files can contain multiple sizes, we need at least a minimum of 60px (16px is ok, as long as 60px are present as well)
if (req.file.dimensions.width <= 60) {
return next(new errors.ValidationError({message: i18n.t('errors.api.icons.invalidFile', {extensions: iconExtensions})}));
}

// CASE: icon needs to be smaller than 1000px
if (req.file.dimensions.width > 1000) {
return next(new errors.ValidationError({message: i18n.t('errors.api.icons.fileTooLarge', {extensions: iconExtensions})}));
return next(new errors.ValidationError({message: i18n.t('errors.api.icons.invalidFile', {extensions: iconExtensions})}));
}

next();
Expand Down
Binary file modified core/server/public/favicon.ico
100644 → 100755
Binary file not shown.
6 changes: 1 addition & 5 deletions core/server/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,7 @@
},
"icons": {
"missingFile": "Please select an icon.",
"fileSizeTooLarge": "Please select an icon file smaller than 100kb.",
"iconNotSquare": "The icon needs to be a square.",
"fileTooLarge": "Please select an icon file smaller than 1000px.",
"fileTooSmall": "Please select an icon file larger than 32px.",
"invalidFile": "Please select a valid icon file.",
"invalidFile": "Blog icon must be a square .ico or .png file between 60px – 1,000px, under 100kb.",
"couldNotGetSize": "Couldn/'t get icon dimensions"
},
"users": {
Expand Down
4 changes: 2 additions & 2 deletions core/test/functional/routes/api/upload_icon_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('Upload Icon API', function () {
request.post(testUtils.API.getApiQuery('uploads/icon'))
.set('Authorization', 'Bearer ' + accesstoken)
.expect('Content-Type', /json/)
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/favicon_32x_single.ico'))
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/favicon_64x_single.ico'))
.expect(200)
.end(function (err, res) {
if (err) {
Expand Down Expand Up @@ -151,7 +151,7 @@ describe('Upload Icon API', function () {
.set('Authorization', 'Bearer ' + accesstoken)
.expect('Content-Type', /json/)
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/favicon_size_too_large.png'))
.expect(413)
.expect(422)
.end(function (err) {
if (err) {
return done(err);
Expand Down
2 changes: 1 addition & 1 deletion core/test/unit/middleware/serve-favicon_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('Serve Favicon', function () {
statusCode.should.eql(200);
},
end: function (body) {
body.length.should.eql(15086);
body.length.should.eql(34494);
done();
}
};
Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified core/test/utils/fixtures/images/favicon_multi_sizes.ico
100644 → 100755
Binary file not shown.

0 comments on commit d9d182f

Please sign in to comment.