Initial commit of document-service

This commit is contained in:
2026-04-23 16:20:58 -05:00
commit 51d60f0032
30 changed files with 4357 additions and 0 deletions

38
app/enums.py Normal file
View 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)