Skip to content

Commit c1a22a5

Browse files
committed
Replace hard coded impl in getImageMimeType
Signed-off-by: Yukai Huang <yukaihuangtw@gmail.com>
1 parent 7a88f9d commit c1a22a5

File tree

1 file changed

+2
-17
lines changed

1 file changed

+2
-17
lines changed

lib/utils.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,14 @@
22
const fs = require('fs')
33
const path = require('path')
44
const bodyParser = require('body-parser')
5+
const mime = require('mime-types')
56

67
exports.isSQLite = function isSQLite (sequelize) {
78
return sequelize.options.dialect === 'sqlite'
89
}
910

1011
exports.getImageMimeType = function getImageMimeType (imagePath) {
11-
const fileExtension = /[^.]+$/.exec(imagePath)
12-
13-
switch (fileExtension[0]) {
14-
case 'bmp':
15-
return 'image/bmp'
16-
case 'gif':
17-
return 'image/gif'
18-
case 'jpg':
19-
case 'jpeg':
20-
return 'image/jpeg'
21-
case 'png':
22-
return 'image/png'
23-
case 'tiff':
24-
return 'image/tiff'
25-
default:
26-
return undefined
27-
}
12+
return mime.contentType(path.extname(imagePath))
2813
}
2914

3015
exports.isRevealTheme = function isRevealTheme (theme) {

0 commit comments

Comments
 (0)