File tree 1 file changed +24
-30
lines changed
1 file changed +24
-30
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,29 @@ const {
19
19
HTTP_STATUS_OK ,
20
20
} = H2 ;
21
21
22
+ const MIME = {
23
+ 'bin' : 'application/octet-stream' ,
24
+ 'css' : 'text/css' ,
25
+ 'gif' : 'image/gif' ,
26
+ 'htm' : 'text/html' ,
27
+ 'html' : 'text/html' ,
28
+ 'ico' : 'image/vnd.microsoft.icon' ,
29
+ 'jpeg' : 'image/jpeg' ,
30
+ 'jpg' : 'image/jpeg' ,
31
+ 'js' : 'text/javascript' ,
32
+ 'json' : 'application/json' ,
33
+ 'mjs' : 'text/javascript' ,
34
+ 'mp3' : 'audio/mpeg' ,
35
+ 'mp4' : 'video/mp4' ,
36
+ 'pdf' : 'application/pdf' ,
37
+ 'png' : 'image/png' ,
38
+ 'svg' : 'image/svg+xml' ,
39
+ 'txt' : 'text/plain' ,
40
+ 'woff' : 'font/woff' ,
41
+ 'woff2' : 'font/woff2' ,
42
+ 'xml' : 'text/xml' ,
43
+ } ;
44
+
22
45
const FILE_ICON = 'favicon.ico' ;
23
46
const FILE_INDEX = 'index.html' ;
24
47
const HEAD_FILENAME = 'upload-filename' ; // HTTP header to get uploading filename
@@ -38,36 +61,7 @@ const WEB_ROOT = getWebRoot(); // path to './pub/' folder
38
61
function getMimeType ( filename ) {
39
62
const ext = filename . substring ( filename . lastIndexOf ( "." ) + 1 ) ;
40
63
const norm = ( typeof ext === 'string' ) ? ext . toLowerCase ( ) : null ;
41
- switch ( norm ) {
42
- case 'css' :
43
- return 'text/css' ;
44
- case 'htm' :
45
- case 'html' :
46
- return 'text/html' ;
47
- case 'ico' :
48
- return 'image/vnd.microsoft.icon' ;
49
- case 'jpeg' :
50
- case 'jpg' :
51
- return 'image/jpeg' ;
52
- case 'js' :
53
- case 'mjs' :
54
- return 'text/javascript' ;
55
- case 'json' :
56
- return 'application/json' ;
57
- case 'mp3' :
58
- return 'audio/mpeg' ;
59
- case 'mp4' :
60
- return 'video/mp4' ;
61
- case 'pdf' :
62
- return 'application/pdf' ;
63
- case 'png' :
64
- return 'image/png' ;
65
- case 'txt' :
66
- return 'text/plain' ;
67
- case 'xml' :
68
- return 'text/xml' ;
69
- }
70
- return 'application/octet-stream' ;
64
+ return MIME [ norm ] ?? MIME [ 'bin' ] ;
71
65
}
72
66
73
67
/**
You can’t perform that action at this time.
0 commit comments