-
Notifications
You must be signed in to change notification settings - Fork 5
Minio #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minio #8
Changes from all commits
3c38310
ebff30c
87f5d81
fee54a4
5dd900c
829377c
db12640
332073f
0958210
4a6f56a
edddee1
058abd8
8a41d00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |||||||||
| from fastapi import APIRouter, Depends, HTTPException, Request, Response | ||||||||||
| from fastapi import Query | ||||||||||
| import base64 | ||||||||||
| from pydantic import BaseModel | ||||||||||
| from pydantic import BaseModel, Field | ||||||||||
|
|
||||||||||
| from core.utils import get_current_user | ||||||||||
| from infrastructure.app_factory import app_factory | ||||||||||
|
|
@@ -26,7 +26,7 @@ class FileUploadRequest(BaseModel): | |||||||||
| filename: str | ||||||||||
| content_base64: str | ||||||||||
| content_type: Optional[str] = "application/octet-stream" | ||||||||||
| tags: Optional[Dict[str, str]] = {} | ||||||||||
| tags: Optional[Dict[str, str]] = Field(default_factory=dict) | ||||||||||
|
|
||||||||||
|
|
||||||||||
| class FileResponse(BaseModel): | ||||||||||
|
|
@@ -51,12 +51,39 @@ class FileContentResponse(BaseModel): | |||||||||
| tags: Dict[str, str] | ||||||||||
|
|
||||||||||
|
|
||||||||||
| @router.get("/files/healthz") | ||||||||||
| async def files_health_check(): | ||||||||||
| """Health check for files service. | ||||||||||
|
|
||||||||||
| Note: Declared before the dynamic /files/{file_key} route to avoid path capture. | ||||||||||
| """ | ||||||||||
| s3_client = app_factory.get_file_storage() | ||||||||||
| return { | ||||||||||
| "status": "healthy", | ||||||||||
| "service": "files-api", | ||||||||||
| "s3_config": { | ||||||||||
| "endpoint": s3_client.endpoint_url if hasattr(s3_client, 'endpoint_url') else "unknown", | ||||||||||
| "bucket": s3_client.bucket_name if hasattr(s3_client, 'bucket_name') else "unknown" | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
| @router.post("/files", response_model=FileResponse) | ||||||||||
| async def upload_file( | ||||||||||
| request: FileUploadRequest, | ||||||||||
| current_user: str = Depends(get_current_user) | ||||||||||
| ) -> FileResponse: | ||||||||||
| """Upload a file to S3 storage.""" | ||||||||||
| # Validate base64 content size (configurable limit to prevent abuse) | ||||||||||
| try: | ||||||||||
| content_size = len(request.content_base64) * 3 // 4 # approximate decoded size | ||||||||||
|
||||||||||
| content_size = len(request.content_base64) * 3 // 4 # approximate decoded size | |
| # Decode base64 to get the exact size of the file in bytes. | |
| decoded_content = base64.b64decode(request.content_base64, validate=True) | |
| content_size = len(decoded_content) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message combines two distinct failure cases. Split this into separate error messages: 'File manager not available' and 'User email required' for clearer debugging and better user experience.