Spaces:
Running
Running
Update app/routes/file_routes.py
Browse files- app/routes/file_routes.py +44 -28
app/routes/file_routes.py
CHANGED
|
@@ -1,28 +1,44 @@
|
|
| 1 |
-
from fastapi import APIRouter, File, UploadFile, Query
|
| 2 |
-
from fastapi.responses import JSONResponse
|
| 3 |
-
from enum import Enum
|
| 4 |
-
from ..services.storage_service import StorageService
|
| 5 |
-
|
| 6 |
-
router = APIRouter()
|
| 7 |
-
storage_service = StorageService()
|
| 8 |
-
|
| 9 |
-
class ExpirationTime(str, Enum):
|
| 10 |
-
THIRTY_SECONDS = "30s"
|
| 11 |
-
ONE_DAY = "24h"
|
| 12 |
-
THREE_DAYS = "3d"
|
| 13 |
-
FIVE_DAYS = "5d"
|
| 14 |
-
ONE_WEEK = "7d"
|
| 15 |
-
|
| 16 |
-
@router.post("/upload")
|
| 17 |
-
async def upload_file(
|
| 18 |
-
file: UploadFile = File(...),
|
| 19 |
-
expiration: ExpirationTime = Query(..., description="File expiration time")
|
| 20 |
-
):
|
| 21 |
-
result = await storage_service.upload_file(file, expiration)
|
| 22 |
-
return JSONResponse(
|
| 23 |
-
content={
|
| 24 |
-
'message': 'File uploaded successfully',
|
| 25 |
-
'data': result
|
| 26 |
-
},
|
| 27 |
-
status_code=200
|
| 28 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter, File, UploadFile, Query
|
| 2 |
+
from fastapi.responses import JSONResponse
|
| 3 |
+
from enum import Enum
|
| 4 |
+
from ..services.storage_service import StorageService
|
| 5 |
+
|
| 6 |
+
router = APIRouter()
|
| 7 |
+
storage_service = StorageService()
|
| 8 |
+
|
| 9 |
+
class ExpirationTime(str, Enum):
|
| 10 |
+
THIRTY_SECONDS = "30s"
|
| 11 |
+
ONE_DAY = "24h"
|
| 12 |
+
THREE_DAYS = "3d"
|
| 13 |
+
FIVE_DAYS = "5d"
|
| 14 |
+
ONE_WEEK = "7d"
|
| 15 |
+
|
| 16 |
+
@router.post("/upload")
|
| 17 |
+
async def upload_file(
|
| 18 |
+
file: UploadFile = File(...),
|
| 19 |
+
expiration: ExpirationTime = Query(..., description="File expiration time")
|
| 20 |
+
):
|
| 21 |
+
result = await storage_service.upload_file(file, expiration)
|
| 22 |
+
return JSONResponse(
|
| 23 |
+
content={
|
| 24 |
+
'message': 'File uploaded successfully',
|
| 25 |
+
'data': result
|
| 26 |
+
},
|
| 27 |
+
status_code=200
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
@router.get("/health")
|
| 31 |
+
@router.head("/health")
|
| 32 |
+
async def health_check():
|
| 33 |
+
"""
|
| 34 |
+
Simple health check endpoint to keep the service awake.
|
| 35 |
+
Returns a 200 OK status with a basic message.
|
| 36 |
+
"""
|
| 37 |
+
return {
|
| 38 |
+
"status": "alive",
|
| 39 |
+
"message": "File Storage Service is Running",
|
| 40 |
+
"service": "File Upload",
|
| 41 |
+
"supported_expiration_times": [
|
| 42 |
+
"30s", "24h", "3d", "5d", "7d"
|
| 43 |
+
]
|
| 44 |
+
}
|