@@ -7,7 +7,7 @@ var fileService = {};
77
88fileService . get = function ( req , res ) {
99 var fileFullPath = req . params . file_id ;
10- var mimeType = mime . lookup ( fileFullPath ) || '' ;
10+ var mimeType = mime . lookup ( fileFullPath ) || extraTypes ( fileFullPath ) || '' ;
1111
1212 // fix case for ES6 files (currently, highlight them as regular javascript)
1313 if ( ! mimeType && fileFullPath . toLowerCase ( ) . endsWith ( 'es6' ) ) {
@@ -39,7 +39,8 @@ fileService.get = function(req, res) {
3939 } else {
4040 var file = {
4141 content : data ,
42- mimeType : mimeType
42+ mimeType : mimeType ,
43+ tags : fileService . getFileTags ( fileFullPath )
4344 } ;
4445 res . json ( file ) ;
4546 console . time ( ) . tag ( 'FILE CONTENT' )
@@ -128,4 +129,76 @@ fileService.putExtraArg = function(req, res) {
128129
129130} ;
130131
132+ fileService . getFileTags = function ( filepath ) {
133+ var fileTags = [ ] ;
134+ var filenameRegex = / [ \\ \/ ] ( [ ^ \\ \/ ] + ) $ / ;
135+ var match = filenameRegex . exec ( filepath ) ;
136+ var match = match . length > 0 ? match [ 1 ] : undefined ;
137+ if ( filepath . indexOf ( '.' ) !== - 1 && match ) {
138+ var tags = match . split ( '.' ) ;
139+ // remove the extension
140+ tags . pop ( ) ;
141+
142+ tags . forEach ( function ( tag ) {
143+ switch ( tag ) {
144+ case 'min' :
145+ fileTags . push ( 'minified' ) ;
146+ break ;
147+ case 'conf' :
148+ case 'config' :
149+ case 'configuration' :
150+ fileTags . push ( 'configuration' ) ;
151+ break ;
152+ case 'test' :
153+ case 'spec' :
154+ case 'specs' :
155+ fileTags . push ( 'test' ) ;
156+ break ;
157+ case 'template' :
158+ case 'partial' :
159+ fileTags . push ( 'template' ) ;
160+ break ;
161+ case 'controller' :
162+ case 'ctrl' :
163+ fileTags . push ( 'controller' ) ;
164+ break ;
165+ case 'service' :
166+ fileTags . push ( 'service' ) ;
167+ break ;
168+ case 'module' :
169+ fileTags . push ( 'module' ) ;
170+ break ;
171+ case 'routes' :
172+ case 'route' :
173+ fileTags . push ( 'routes' ) ;
174+ break ;
175+ case 'directive' :
176+ fileTags . push ( 'directive' ) ;
177+ break ;
178+ }
179+ } ) ;
180+ }
181+ return fileTags ;
182+ } ;
183+
184+ function extraTypes ( filepath ) {
185+ if ( filepath . indexOf ( '.' ) !== - 1 ) {
186+ var extensionStart = filepath . lastIndexOf ( '.' ) + 1 ;
187+ var fileExtension = filepath . substring ( extensionStart , filepath . length ) ;
188+ var mime ;
189+
190+ switch ( fileExtension ) {
191+ case 'nsi' :
192+ mime = 'nsis' ;
193+ break ;
194+ default :
195+ mime = fileExtension ;
196+ }
197+
198+ return 'application/' + mime ;
199+ } else {
200+ return undefined ;
201+ }
202+ }
203+
131204module . exports = fileService ;
0 commit comments