@@ -3,7 +3,80 @@ const cli = require('@cocreate/cli')
3
3
const mime = require ( 'mime-types' )
4
4
const fs = require ( 'fs' ) ;
5
5
const path = require ( 'path' ) ;
6
-
6
+ const mimeTypes = {
7
+ ".aac" : "audio/aac" ,
8
+ ".abw" : "application/x-abiword" ,
9
+ ".arc" : "application/x-freearc" ,
10
+ ".avi" : "video/x-msvideo" ,
11
+ ".azw" : "application/vnd.amazon.ebook" ,
12
+ ".bin" : "application/octet-stream" ,
13
+ ".bmp" : "image/bmp" ,
14
+ ".bz" : "application/x-bzip" ,
15
+ ".bz2" : "application/x-bzip2" ,
16
+ ".csh" : "application/x-csh" ,
17
+ ".css" : "text/css" ,
18
+ ".csv" : "text/csv" ,
19
+ ".doc" : "application/msword" ,
20
+ ".docx" : "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ,
21
+ ".eot" : "application/vnd.ms-fontobject" ,
22
+ ".epub" : "application/epub+zip" ,
23
+ ".gif" : "image/gif" ,
24
+ ".htm" : "text/html" ,
25
+ ".html" : "text/html" ,
26
+ ".ico" : "image/vnd.microsoft.icon" ,
27
+ ".ics" : "text/calendar" ,
28
+ ".jar" : "application/java-archive" ,
29
+ ".jpeg" : "image/jpeg" ,
30
+ ".jpg" : "image/jpeg" ,
31
+ ".js" : "text/javascript" ,
32
+ ".json" : "application/json" ,
33
+ ".jsonld" : "application/ld+json" ,
34
+ ".mid" : "audio/midi" ,
35
+ ".midi" : "audio/midi" ,
36
+ ".mjs" : "text/javascript" ,
37
+ ".mp3" : "audio/mpeg" ,
38
+ ".mp4" : "video/mp4" ,
39
+ ".mpeg" : "video/mpeg" ,
40
+ ".mpkg" : "application/vnd.apple.installer+xml" ,
41
+ ".odp" : "application/vnd.oasis.opendocument.presentation" ,
42
+ ".ods" : "application/vnd.oasis.opendocument.spreadsheet" ,
43
+ ".odt" : "application/vnd.oasis.opendocument.text" ,
44
+ ".oga" : "audio/ogg" ,
45
+ ".ogv" : "video/ogg" ,
46
+ ".ogx" : "application/ogg" ,
47
+ ".otf" : "font/otf" ,
48
+ ".png" : "image/png" ,
49
+ ".pdf" : "application/pdf" ,
50
+ ".ppt" : "application/vnd.ms-powerpoint" ,
51
+ ".pptx" : "application/vnd.openxmlformats-officedocument.presentationml.presentation" ,
52
+ ".rar" : "application/x-rar-compressed" ,
53
+ ".rtf" : "application/rtf" ,
54
+ ".sh" : "application/x-sh" ,
55
+ ".svg" : "image/svg+xml" ,
56
+ ".swf" : "application/x-shockwave-flash" ,
57
+ ".tar" : "application/x-tar" ,
58
+ ".tif" : "image/tiff" ,
59
+ ".tiff" : "image/tiff" ,
60
+ ".ts" : "video/mp2t" ,
61
+ ".ttf" : "font/ttf" ,
62
+ ".txt" : "text/plain" ,
63
+ ".vsd" : "application/vnd.visio" ,
64
+ ".wav" : "audio/wav" ,
65
+ ".weba" : "audio/webm" ,
66
+ ".webm" : "video/webm" ,
67
+ ".webp" : "image/webp" ,
68
+ ".woff" : "font/woff" ,
69
+ ".woff2" : "font/woff2" ,
70
+ ".xhtml" : "application/xhtml+xml" ,
71
+ ".xls" : "application/vnd.ms-excel" ,
72
+ ".xlsx" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ,
73
+ ".xml" : "application/xml" ,
74
+ ".xul" : "application/vnd.mozilla.xul+xml" ,
75
+ ".zip" : "application/zip" ,
76
+ ".3gp" : "video/3gpp" ,
77
+ ".3g2" : "video/3gpp2" ,
78
+ ".7z" : "application/x-7z-compressed"
79
+ }
7
80
8
81
module . exports = async function file ( CoCreateConfig ) {
9
82
@@ -109,7 +182,8 @@ module.exports = async function file(CoCreateConfig) {
109
182
if ( parentDirectoryOnly && index ) {
110
183
parentDirectoryOnly = parentDirectoryOnly . substring ( index )
111
184
}
112
- let mimeType = mime . lookup ( `${ file } ` )
185
+ const fileExtension = path . extname ( file ) ;
186
+ let mimeType = mimeTypes [ fileExtension ]
113
187
let pathName = '' ;
114
188
115
189
if ( ! directoryName && directory . document && directory . document . directory )
@@ -254,7 +328,9 @@ module.exports = async function file(CoCreateConfig) {
254
328
continue
255
329
256
330
let read_type = 'utf8'
257
- let mime_type = mime . lookup ( entry ) || 'text/html' ;
331
+ const fileExtension = path . extname ( entry ) ;
332
+ let mime_type = mimeTypes [ fileExtension ] || 'text/html'
333
+
258
334
if ( / ^ ( i m a g e | a u d i o | v i d e o ) \/ [ - + . \w ] + / . test ( mime_type ) ) {
259
335
read_type = 'base64'
260
336
}
0 commit comments