This commit is contained in:
@@ -46,13 +46,13 @@ async def upload_document(
|
|||||||
s3_key = utils.document_s3_key(org_id, document_id, sanitized_filename)
|
s3_key = utils.document_s3_key(org_id, document_id, sanitized_filename)
|
||||||
|
|
||||||
# Prepare metadata
|
# Prepare metadata
|
||||||
metadata_dict = {
|
metadata_dict = {
|
||||||
"org_id": org_id,
|
"org_id": org_id,
|
||||||
"document_type": document_type.value,
|
"document_type": document_type.value,
|
||||||
"filename": sanitized_filename,
|
"filename": sanitized_filename,
|
||||||
"file_size": str(file_size),
|
"file_size": str(file_size),
|
||||||
"created_at": datetime.utcnow().isoformat()
|
"created_at": datetime.utcnow().isoformat()
|
||||||
}
|
}
|
||||||
|
|
||||||
# Upload to S3
|
# Upload to S3
|
||||||
try:
|
try:
|
||||||
@@ -65,8 +65,8 @@ async def upload_document(
|
|||||||
# Generate download URL
|
# Generate download URL
|
||||||
download_url = s3.presigned_download_url(s3_key)
|
download_url = s3.presigned_download_url(s3_key)
|
||||||
|
|
||||||
# Create metadata response
|
# Create metadata response
|
||||||
metadata = DocumentMetadata(
|
metadata = DocumentMetadata(
|
||||||
document_id=document_id,
|
document_id=document_id,
|
||||||
org_id=org_id,
|
org_id=org_id,
|
||||||
document_type=document_type,
|
document_type=document_type,
|
||||||
@@ -76,7 +76,7 @@ async def upload_document(
|
|||||||
s3_key=s3_key,
|
s3_key=s3_key,
|
||||||
created_at=datetime.utcnow(),
|
created_at=datetime.utcnow(),
|
||||||
updated_at=datetime.utcnow()
|
updated_at=datetime.utcnow()
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.info(f"Upload completed - document_id: {document_id}")
|
logger.info(f"Upload completed - document_id: {document_id}")
|
||||||
return UploadResponse(document_id=document_id, metadata=metadata, download_url=download_url)
|
return UploadResponse(document_id=document_id, metadata=metadata, download_url=download_url)
|
||||||
@@ -123,13 +123,13 @@ async def rewrite_document(
|
|||||||
logger.error(f"Organization mismatch for document: {document_id}")
|
logger.error(f"Organization mismatch for document: {document_id}")
|
||||||
raise HTTPException(status_code=403, detail="Organization mismatch")
|
raise HTTPException(status_code=403, detail="Organization mismatch")
|
||||||
|
|
||||||
# Prepare metadata
|
# Prepare metadata
|
||||||
metadata_dict = {
|
metadata_dict = {
|
||||||
"org_id": org_id,
|
"org_id": org_id,
|
||||||
"document_type": document_type.value,
|
"document_type": document_type.value,
|
||||||
"filename": file.filename,
|
"filename": sanitized_filename,
|
||||||
"file_size": str(file_size),
|
"file_size": str(file_size),
|
||||||
"updated_at": datetime.utcnow().isoformat()
|
"updated_at": datetime.utcnow().isoformat()
|
||||||
}
|
}
|
||||||
|
|
||||||
# Upload to S3 (overwrites existing)
|
# Upload to S3 (overwrites existing)
|
||||||
@@ -143,17 +143,17 @@ async def rewrite_document(
|
|||||||
# Generate download URL
|
# Generate download URL
|
||||||
download_url = s3.presigned_download_url(s3_key)
|
download_url = s3.presigned_download_url(s3_key)
|
||||||
|
|
||||||
# Create metadata response
|
# Create metadata response
|
||||||
metadata = DocumentMetadata(
|
metadata = DocumentMetadata(
|
||||||
document_id=document_id,
|
document_id=document_id,
|
||||||
org_id=org_id,
|
org_id=org_id,
|
||||||
document_type=document_type,
|
document_type=document_type,
|
||||||
filename=file.filename,
|
filename=sanitized_filename,
|
||||||
content_type=detected_content_type,
|
content_type=detected_content_type,
|
||||||
file_size=file_size,
|
file_size=file_size,
|
||||||
s3_key=s3_key,
|
s3_key=s3_key,
|
||||||
created_at=datetime.fromisoformat(existing_metadata.get("created_at", datetime.utcnow().isoformat())),
|
created_at=datetime.fromisoformat(existing_metadata.get("created_at", datetime.utcnow().isoformat())),
|
||||||
updated_at=datetime.utcnow()
|
updated_at=datetime.utcnow()
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.info(f"Rewrite completed - document_id: {document_id}")
|
logger.info(f"Rewrite completed - document_id: {document_id}")
|
||||||
|
|||||||
Reference in New Issue
Block a user