From 1af3727fefa43b814f99161bddcc6ee2a000be6c Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sun, 7 May 2017 18:54:18 +0800 Subject: [PATCH 1/5] Remove npm install in heroku build since heroku detects yarn.lock automatically --- bin/heroku | 2 -- 1 file changed, 2 deletions(-) diff --git a/bin/heroku b/bin/heroku index 1228b28..2472734 100755 --- a/bin/heroku +++ b/bin/heroku @@ -3,8 +3,6 @@ set -e if [ "$BUILD_ASSETS" = true ]; then - BUILD_ASSETS=false npm install - # setup config files cat << EOF > .sequelizerc var path = require('path'); From be7335e92a0696e9c5e4cad3c98465869a64b27e Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sun, 7 May 2017 19:07:03 +0800 Subject: [PATCH 2/5] Remove postdeploy migration --- app.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/app.json b/app.json index 0ed11d7..e09d4c0 100644 --- a/app.json +++ b/app.json @@ -10,9 +10,6 @@ "repository": "https://github.com/hackmdio/hackmd", "logo": "https://github.com/hackmdio/hackmd/raw/master/public/hackmd-icon-1024.png", "success_url": "/", - "scripts": { - "postdeploy": "./node_modules/.bin/sequelize db:migrate" - }, "env": { "BUILD_ASSETS": { "description": "Our build script variable", From 03ef1bf4f02684824e14c08ea6d6926fa4aab579 Mon Sep 17 00:00:00 2001 From: LluisArevalo Date: Mon, 8 May 2017 10:22:52 +0200 Subject: [PATCH 3/5] Add Content-Type to the images uploaded to AWS S3 --- app.js | 3 +++ lib/utils.js | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/app.js b/app.js index 677d3fa..91e17ad 100644 --- a/app.js +++ b/app.js @@ -548,6 +548,9 @@ app.post('/uploadimage', function (req, res) { Body: buffer } + var mimeType = getImageMimeType(files.image.path) + if (mimeType) { params.ContentType = mimeType } + s3.putObject(params, function (err, data) { if (err) { logger.error(err) diff --git a/lib/utils.js b/lib/utils.js index 6c36549..5254166 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -3,3 +3,23 @@ exports.isSQLite = function isSQLite (sequelize) { return sequelize.options.dialect === 'sqlite' } + +exports.getImageMimeType = function getImageMimeType (imagePath) { + var fileExtension = /[^.]+$/.exec(imagePath) + + switch (fileExtension[0]) { + case "bmp": + return "image/bmp" + case "gif": + return "image/gif" + case "jpg": + case "jpeg": + return "image/jpeg" + case "png": + return "image/png" + case "tiff": + return "image/tiff" + default: + return undefined + } +} From 6e277100ca3bb75bbae15a94b1b805c209570a62 Mon Sep 17 00:00:00 2001 From: LluisArevalo Date: Mon, 8 May 2017 10:52:30 +0200 Subject: [PATCH 4/5] Add reference to utils library --- app.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app.js b/app.js index 91e17ad..dbbecc9 100644 --- a/app.js +++ b/app.js @@ -22,6 +22,9 @@ var i18n = require('i18n') var flash = require('connect-flash') var validator = require('validator') +// utils +var getImageMimeType = require('./lib/utils.js').getImageMimeType + // core var config = require('./lib/config.js') var logger = require('./lib/logger.js') From 6bf32afb0bd57bd3ee43670a06a2d0c5448cb2c4 Mon Sep 17 00:00:00 2001 From: LluisArevalo Date: Mon, 8 May 2017 11:00:45 +0200 Subject: [PATCH 5/5] Use single quotes --- lib/utils.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 5254166..d9289dc 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -8,17 +8,17 @@ exports.getImageMimeType = function getImageMimeType (imagePath) { var fileExtension = /[^.]+$/.exec(imagePath) switch (fileExtension[0]) { - case "bmp": - return "image/bmp" - case "gif": - return "image/gif" - case "jpg": - case "jpeg": - return "image/jpeg" - case "png": - return "image/png" - case "tiff": - return "image/tiff" + case 'bmp': + return 'image/bmp' + case 'gif': + return 'image/gif' + case 'jpg': + case 'jpeg': + return 'image/jpeg' + case 'png': + return 'image/png' + case 'tiff': + return 'image/tiff' default: return undefined }