Skip to content

Commit c0f13cf

Browse files
committed
Merge branch 'master' of https://github.com/jackycute/HackMD
2 parents be99350 + 90631df commit c0f13cf

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ var i18n = require('i18n')
2222
var flash = require('connect-flash')
2323
var validator = require('validator')
2424

25+
// utils
26+
var getImageMimeType = require('./lib/utils.js').getImageMimeType
27+
2528
// core
2629
var config = require('./lib/config.js')
2730
var logger = require('./lib/logger.js')
@@ -548,6 +551,9 @@ app.post('/uploadimage', function (req, res) {
548551
Body: buffer
549552
}
550553

554+
var mimeType = getImageMimeType(files.image.path)
555+
if (mimeType) { params.ContentType = mimeType }
556+
551557
s3.putObject(params, function (err, data) {
552558
if (err) {
553559
logger.error(err)

app.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
"repository": "https://github.com/hackmdio/hackmd",
1111
"logo": "https://github.com/hackmdio/hackmd/raw/master/public/hackmd-icon-1024.png",
1212
"success_url": "/",
13-
"scripts": {
14-
"postdeploy": "./node_modules/.bin/sequelize db:migrate"
15-
},
1613
"env": {
1714
"BUILD_ASSETS": {
1815
"description": "Our build script variable",

bin/heroku

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
set -e
44

55
if [ "$BUILD_ASSETS" = true ]; then
6-
BUILD_ASSETS=false npm install
7-
86
# setup config files
97
cat << EOF > .sequelizerc
108
var path = require('path');

lib/utils.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,23 @@
33
exports.isSQLite = function isSQLite (sequelize) {
44
return sequelize.options.dialect === 'sqlite'
55
}
6+
7+
exports.getImageMimeType = function getImageMimeType (imagePath) {
8+
var fileExtension = /[^.]+$/.exec(imagePath)
9+
10+
switch (fileExtension[0]) {
11+
case 'bmp':
12+
return 'image/bmp'
13+
case 'gif':
14+
return 'image/gif'
15+
case 'jpg':
16+
case 'jpeg':
17+
return 'image/jpeg'
18+
case 'png':
19+
return 'image/png'
20+
case 'tiff':
21+
return 'image/tiff'
22+
default:
23+
return undefined
24+
}
25+
}

0 commit comments

Comments
 (0)