refactor: remove local getFileType function and use imported utility
This commit is contained in:
		
							parent
							
								
									ad24c76a70
								
							
						
					
					
						commit
						f2d2268039
					
				| @ -1,6 +1,7 @@ | |||||||
| "use client"; | "use client"; | ||||||
| 
 | 
 | ||||||
| import { useEffect, useState } from "react"; | import { useEffect, useState } from "react"; | ||||||
|  | import { getFileType } from "~/utils/fileType"; // Adjust the import path as necessary
 | ||||||
| 
 | 
 | ||||||
| interface FilePreviewProps { | interface FilePreviewProps { | ||||||
|   fileId: string; |   fileId: string; | ||||||
| @ -51,35 +52,6 @@ export function FilePreview({ fileId, fileType }: FilePreviewProps) { | |||||||
|   if (!mediaSrc) { |   if (!mediaSrc) { | ||||||
|     return <div>Loading...</div>; |     return <div>Loading...</div>; | ||||||
|   } |   } | ||||||
|   const getFileType = (extension: string): string => { |  | ||||||
|     const fileTypes: Record<string, string> = { |  | ||||||
|       ".mp4": "video/mp4", |  | ||||||
|       ".webm": "video/webm", |  | ||||||
|       ".ogg": "video/ogg", |  | ||||||
|       ".jpg": "image/jpeg", |  | ||||||
|       ".jpeg": "image/jpeg", |  | ||||||
|       ".png": "image/png", |  | ||||||
|       ".gif": "image/gif", |  | ||||||
|       ".svg": "image/svg+xml", |  | ||||||
|       ".mp3": "audio/mpeg", |  | ||||||
|       ".wav": "audio/wav", |  | ||||||
|       ".zip": "archive/zip", |  | ||||||
|       ".rar": "archive/rar", |  | ||||||
|       ".pdf": "text/pdf", |  | ||||||
|       ".txt": "text/plain", |  | ||||||
|       ".c" : "code/c", |  | ||||||
|       ".cpp" : "code/cpp", |  | ||||||
|       ".py" : "code/python", |  | ||||||
|       ".js" : "code/javascript", |  | ||||||
|       ".html" : "code/html", |  | ||||||
|       ".css" : "code/css", |  | ||||||
|       ".md" : "markdown/markdown", |  | ||||||
|       ".json" : "code/json", |  | ||||||
|       ".xml" : "code/xml", |  | ||||||
|       ".csv" : "code/csv", |  | ||||||
|     }; |  | ||||||
|     return fileTypes[extension] || "unknown"; |  | ||||||
|   }; |  | ||||||
| 
 | 
 | ||||||
|   if (getFileType(fileType).startsWith("video")) { |   if (getFileType(fileType).startsWith("video")) { | ||||||
|     return ( |     return ( | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user