11from typing import Any
2+
3+ from fastapi import APIRouter , BackgroundTasks , File , HTTPException , UploadFile
4+
25from app .api .deps import CurrentUser , SessionDep
36from app .models import Document , DocumentCreate , DocumentPublic
4- from fastapi import APIRouter , BackgroundTasks , File , UploadFile , HTTPException
5- from app .s3 import upload_file_to_s3 , generate_s3_url
7+ from app .s3 import generate_s3_url , upload_file_to_s3
68
79router = APIRouter (prefix = "/documents" , tags = ["documents" ])
8-
10+
911@router .post ("/" , response_model = DocumentPublic )
1012def create_document (
1113 * , session : SessionDep , current_user : CurrentUser ,
12- background_tasks : BackgroundTasks ,
13- file : UploadFile = File (...),
14+ background_tasks : BackgroundTasks , # noqa: ARG001
15+ file : UploadFile = File (...),
1416) -> Any :
1517 key = None
1618 try :
17- user_id = current_user .id
1819 key = upload_file_to_s3 (file , str (current_user .id ))
1920 except Exception as e :
2021 raise HTTPException (500 , f"Failed to upload file. Error: { str (e )} " )
2122
2223 try :
2324 url = generate_s3_url (key )
24- except Exception as e :
25+ except Exception :
2526 raise HTTPException (500 , f"Could not generate URL for file key: { key } " )
2627
2728 document_in = DocumentCreate (
2829 filename = file .filename ,
2930 content_type = file .content_type ,
30- size = file .size ,
31+ size = file .size ,
3132 s3_url = url ,
3233 )
3334
@@ -42,4 +43,4 @@ def create_document(
4243 print ("Document created, starting background task..." )
4344 # background_tasks.add_task(generate_questions, document.id)
4445
45- return document
46+ return document
0 commit comments