Working Sampler and samples routes working
Signed-off-by: Felipe Cardoso <felipe.cardoso@hotmail.it>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from typing import List
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Query
|
||||
from fastapi.responses import Response
|
||||
|
||||
from app.models.sample import Sample
|
||||
from app.services.sample_manager import SampleManager
|
||||
@@ -8,7 +9,6 @@ from app.services.sample_manager import SampleManager
|
||||
router = APIRouter()
|
||||
sample_manager = SampleManager()
|
||||
|
||||
|
||||
@router.get("/list", response_model=List[Sample])
|
||||
async def list_samples(
|
||||
limit: int = Query(20, ge=1, le=100),
|
||||
@@ -22,9 +22,10 @@ async def list_samples(
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.get("/latest", response_model=List[Sample])
|
||||
async def get_latest_samples(count: int = Query(5, ge=1, le=20)):
|
||||
async def get_latest_samples(
|
||||
count: int = Query(5, ge=1, le=20)
|
||||
):
|
||||
"""
|
||||
Get the most recent sample images
|
||||
"""
|
||||
@@ -32,3 +33,28 @@ async def get_latest_samples(count: int = Query(5, ge=1, le=20)):
|
||||
return await sample_manager.get_latest_samples(count)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.get("/image/{filename}")
|
||||
async def get_sample_image(filename: str):
|
||||
"""
|
||||
Get a specific sample image
|
||||
"""
|
||||
try:
|
||||
image_data = await sample_manager.get_sample_data(filename)
|
||||
|
||||
# Try to determine content type from filename
|
||||
content_type = "image/jpeg" # default
|
||||
if filename.lower().endswith('.png'):
|
||||
content_type = "image/png"
|
||||
elif filename.lower().endswith('.gif'):
|
||||
content_type = "image/gif"
|
||||
|
||||
return Response(
|
||||
content=bytes(image_data),
|
||||
media_type=content_type
|
||||
)
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
Reference in New Issue
Block a user