Initial commit of document-service
This commit is contained in:
38
app/enums.py
Normal file
38
app/enums.py
Normal file
@@ -0,0 +1,38 @@
|
||||
from enum import Enum
|
||||
|
||||
class DocumentType(str, Enum):
|
||||
PDF = "pdf"
|
||||
DOCX = "docx"
|
||||
XLSX = "xlsx"
|
||||
JPG = "jpg"
|
||||
JPEG = "jpeg"
|
||||
PNG = "png"
|
||||
GIF = "gif"
|
||||
|
||||
@classmethod
|
||||
def from_mime_type(cls, mime_type: str) -> "DocumentType":
|
||||
"""Map MIME type to DocumentType"""
|
||||
mapping = {
|
||||
"application/pdf": cls.PDF,
|
||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": cls.DOCX,
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": cls.XLSX,
|
||||
"image/jpeg": cls.JPG,
|
||||
"image/png": cls.PNG,
|
||||
"image/gif": cls.GIF,
|
||||
}
|
||||
return mapping.get(mime_type.lower())
|
||||
|
||||
@classmethod
|
||||
def from_extension(cls, filename: str) -> "DocumentType":
|
||||
"""Map file extension to DocumentType"""
|
||||
ext = filename.split(".")[-1].lower()
|
||||
mapping = {
|
||||
"pdf": cls.PDF,
|
||||
"docx": cls.DOCX,
|
||||
"xlsx": cls.XLSX,
|
||||
"jpg": cls.JPG,
|
||||
"jpeg": cls.JPEG,
|
||||
"png": cls.PNG,
|
||||
"gif": cls.GIF,
|
||||
}
|
||||
return mapping.get(ext)
|
||||
Reference in New Issue
Block a user