diff --git a/backend/utils/files.py b/backend/utils/files.py index 1dd2519..00d66b7 100644 --- a/backend/utils/files.py +++ b/backend/utils/files.py @@ -13,3 +13,54 @@ def get_mime_type(file_path: str) -> str: """ mime_type, encoding = mimetypes.guess_type(file_path) return mime_type + + +def categorize_mime_type(mime_type: str) -> str: + image_types = { + "image/jpeg", + "image/png", + "image/bmp", + "image/tiff", + "image/webp", + "image/svg+xml", + "image/heif", + "image/heic", + } + gif_types = {"image/gif"} + video_types = { + "video/mp4", + "video/mpeg", + "video/quicktime", + "video/x-msvideo", + "video/x-matroska", + "video/webm", + "video/ogg", + } + flash_types = {"application/x-shockwave-flash", "application/vnd.adobe.flash.movie"} + archive_types = { + "application/zip", + "application/x-rar-compressed", + "application/x-tar", + "application/gzip", + "application/x-7z-compressed", + "application/x-bzip2", + } + pdf_types = {"application/pdf"} + audio_types = {"audio/mpeg", "audio/wav", "audio/ogg", "audio/flac", "audio/aac"} + + if mime_type in image_types: + return "image" + elif mime_type in gif_types: + return "gif" + elif mime_type in video_types: + return "video" + elif mime_type in flash_types: + return "flash" + elif mime_type in archive_types: + return "archive" + elif mime_type in pdf_types: + return "pdf" + elif mime_type in audio_types: + return "audio" + else: + return "other"