@@ -3,7 +3,80 @@ const cli = require('@cocreate/cli')
33const mime = require ( 'mime-types' )
44const fs = require ( 'fs' ) ;
55const 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+ }
780
881module . exports = async function file ( CoCreateConfig ) {
982
@@ -109,7 +182,8 @@ module.exports = async function file(CoCreateConfig) {
109182 if ( parentDirectoryOnly && index ) {
110183 parentDirectoryOnly = parentDirectoryOnly . substring ( index )
111184 }
112- let mimeType = mime . lookup ( `${ file } ` )
185+ const fileExtension = path . extname ( file ) ;
186+ let mimeType = mimeTypes [ fileExtension ]
113187 let pathName = '' ;
114188
115189 if ( ! directoryName && directory . document && directory . document . directory )
@@ -254,7 +328,9 @@ module.exports = async function file(CoCreateConfig) {
254328 continue
255329
256330 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+
258334 if ( / ^ ( i m a g e | a u d i o | v i d e o ) \/ [ - + . \w ] + / . test ( mime_type ) ) {
259335 read_type = 'base64'
260336 }
0 commit comments