summaryrefslogtreecommitdiff
path: root/lib/worker/mimeFromExtension.js
blob: 16194917760971c298f705bae03bf429e8d28b22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module.exports = function mimeFromExtension (file) {
  const fpartz = file.split('.')
  const ext = fpartz[fpartz.length-1]
  let mime, type;
  switch (ext.toLowerCase()) {
    case 'mp3':
      mime = 'audio/mp3'
      type = 'audio'
      break
    case 'wav':
      mime = 'audio/wav'
      type = 'audio'
      break
    case 'aif':
    case 'aiff':
      mime = 'audio/aiff'
      type = 'audio'
      break

    case 'jpg':
    case 'jpeg':
      mime = 'image/jpeg'
      type = 'image'
      break
    case 'gif':
      mime = 'image/gif'
      type = 'image'
      break
    case 'png':
      mime = 'image/png'
      type = 'image'
      break

    case 'txt':
      mime = 'text/plain'
      type = 'text'
      break
    case 'html':
      mime = 'text/html'
      type = 'text'
      break
  }
  return { type, mime }
}