Fix PDF pages route ordering for correct path matching
Move /files/{storage_key}/pages endpoint before the base /files/{storage_key}
endpoint so FastAPI matches the more specific route first.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
d97be02b0b
commit
53351c86f3
1 changed files with 30 additions and 29 deletions
|
|
@ -647,35 +647,7 @@ async def list_agencies(
|
|||
return [AgencyResponse(id=a.id, name=a.name) for a in agencies]
|
||||
|
||||
|
||||
# File download endpoint
|
||||
@router.get("/files/{storage_key:path}")
|
||||
async def get_file(
|
||||
storage_key: str,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
user: dict = Depends(get_current_user),
|
||||
):
|
||||
"""Retrieve a stored file by its storage key."""
|
||||
file_data = await storage_service.get_file(storage_key)
|
||||
if file_data is None:
|
||||
raise HTTPException(status_code=404, detail="File not found")
|
||||
|
||||
# Determine content type from extension
|
||||
extension = storage_key.split('.')[-1].lower() if '.' in storage_key else ''
|
||||
content_types = {
|
||||
'png': 'image/png',
|
||||
'jpg': 'image/jpeg',
|
||||
'jpeg': 'image/jpeg',
|
||||
'gif': 'image/gif',
|
||||
'webp': 'image/webp',
|
||||
'svg': 'image/svg+xml',
|
||||
'pdf': 'application/pdf',
|
||||
}
|
||||
return Response(
|
||||
content=file_data,
|
||||
media_type=content_types.get(extension, 'application/octet-stream'),
|
||||
)
|
||||
|
||||
|
||||
# PDF pages endpoint (must be defined BEFORE the base file endpoint for correct routing)
|
||||
@router.get("/files/{storage_key:path}/pages")
|
||||
async def get_pdf_pages(
|
||||
storage_key: str,
|
||||
|
|
@ -709,6 +681,35 @@ async def get_pdf_pages(
|
|||
}
|
||||
|
||||
|
||||
# File download endpoint
|
||||
@router.get("/files/{storage_key:path}")
|
||||
async def get_file(
|
||||
storage_key: str,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
user: dict = Depends(get_current_user),
|
||||
):
|
||||
"""Retrieve a stored file by its storage key."""
|
||||
file_data = await storage_service.get_file(storage_key)
|
||||
if file_data is None:
|
||||
raise HTTPException(status_code=404, detail="File not found")
|
||||
|
||||
# Determine content type from extension
|
||||
extension = storage_key.split('.')[-1].lower() if '.' in storage_key else ''
|
||||
content_types = {
|
||||
'png': 'image/png',
|
||||
'jpg': 'image/jpeg',
|
||||
'jpeg': 'image/jpeg',
|
||||
'gif': 'image/gif',
|
||||
'webp': 'image/webp',
|
||||
'svg': 'image/svg+xml',
|
||||
'pdf': 'application/pdf',
|
||||
}
|
||||
return Response(
|
||||
content=file_data,
|
||||
media_type=content_types.get(extension, 'application/octet-stream'),
|
||||
)
|
||||
|
||||
|
||||
# Support email endpoint (public - no auth required for login page access)
|
||||
@router.post("/support/email")
|
||||
async def send_support_email(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue