20 lines
		
	
	
		
			539 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			20 lines
		
	
	
		
			539 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import path from 'path';
 | |
| // 获取文件的 content-type
 | |
| export const getContentType = (filePath: string) => {
 | |
|   const extname = path.extname(filePath);
 | |
|   const contentType = {
 | |
|     '.txt': 'text/plain',
 | |
|     '.html': 'text/html',
 | |
|     '.js': 'text/javascript',
 | |
|     '.css': 'text/css',
 | |
|     '.json': 'application/json',
 | |
|     '.png': 'image/png',
 | |
|     '.jpg': 'image/jpg',
 | |
|     '.gif': 'image/gif',
 | |
|     '.svg': 'image/svg+xml',
 | |
|     '.wav': 'audio/wav',
 | |
|     '.mp4': 'video/mp4',
 | |
|   };
 | |
|   return contentType[extname] || 'application/octet-stream';
 | |
| };
 |