1 | 'use strict'
|
2 |
|
3 | let mime
|
4 |
|
5 | try {
|
6 | mime = require('mime')
|
7 | } catch (e) {}
|
8 |
|
9 | const app = 'application'
|
10 | const html = 'text/html'
|
11 | const jpeg = 'image/jpeg'
|
12 | const text = 'text/plain'
|
13 |
|
14 | const types = {
|
15 | bin: `${app}/octet-stream`,
|
16 | css: 'text/css',
|
17 | gif: 'image/gif',
|
18 | html,
|
19 | htm: html,
|
20 | jpeg,
|
21 | jpg: jpeg,
|
22 | js: `${app}/javascript`,
|
23 | json: `${app}/json`,
|
24 | mp4: 'video/mp4',
|
25 | pdf: `${app}/pdf`,
|
26 | png: 'image/png',
|
27 | svg: 'image/svg+xml',
|
28 | text,
|
29 | txt: text,
|
30 | xml: `${app}/xml`
|
31 | }
|
32 |
|
33 | if (mime && !mime.getType && mime.lookup) {
|
34 | const mimeV1 = mime
|
35 | mime = {
|
36 | getType: extension => mimeV1.lookup(extension)
|
37 | }
|
38 | }
|
39 |
|
40 | if (mime) {
|
41 | module.exports = mime.getType
|
42 | } else {
|
43 | module.exports = extension => types[extension]
|
44 | }
|