Credit Salary works!! Refresh router created, now need to use it in angular Errors should now show up in the frontend.
37 lines
821 B
Python
37 lines
821 B
Python
import uuid
|
|
from io import BytesIO
|
|
|
|
from fastapi import APIRouter, Depends, Security
|
|
from fastapi.responses import StreamingResponse
|
|
from sqlalchemy.orm import Session
|
|
|
|
from ..core.security import get_user
|
|
from ..models.voucher import DbImage
|
|
from ..db.session import SessionLocal
|
|
from ..schemas.auth import UserToken
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
# Dependency
|
|
def get_db() -> Session:
|
|
try:
|
|
db = SessionLocal()
|
|
yield db
|
|
finally:
|
|
db.close()
|
|
|
|
|
|
@router.get("/{id_}/{type_}")
|
|
def db_image(
|
|
id_: uuid.UUID,
|
|
type_: str,
|
|
db: Session = Depends(get_db)
|
|
):
|
|
item = db.query(DbImage).filter(DbImage.id == id_).first()
|
|
if type_ == "thumbnail":
|
|
item = BytesIO(item.thumbnail)
|
|
else:
|
|
item = BytesIO(item.image)
|
|
return StreamingResponse(item, media_type="image/jpeg")
|