InvokeAI/invokeai/app/api/routers/image_files.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.5 KiB
Python
Raw Normal View History

2023-05-21 12:15:44 +00:00
# Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654) and the InvokeAI Team
from fastapi import HTTPException, Path
from fastapi.responses import FileResponse
from fastapi.routing import APIRouter
from invokeai.app.models.image import ImageType
from ..dependencies import ApiDependencies
2023-05-21 12:15:44 +00:00
image_files_router = APIRouter(prefix="/v1/files/images", tags=["images", "files"])
2023-05-21 12:15:44 +00:00
@image_files_router.get("/{image_type}/{image_name}", operation_id="get_image")
async def get_image(
image_type: ImageType = Path(description="The type of the image to get"),
image_name: str = Path(description="The id of the image to get"),
) -> FileResponse:
"""Gets an image"""
2023-05-21 12:15:44 +00:00
try:
path = ApiDependencies.invoker.services.images_new.get_path(
image_type=image_type, image_name=image_name
)
return FileResponse(path)
2023-05-21 12:15:44 +00:00
except Exception as e:
raise HTTPException(status_code=404)
2023-05-21 12:15:44 +00:00
@image_files_router.get(
"/{image_type}/{image_name}/thumbnail", operation_id="get_thumbnail"
)
async def get_thumbnail(
2023-05-21 12:15:44 +00:00
image_type: ImageType = Path(
description="The type of the image whose thumbnail to get"
),
image_name: str = Path(description="The id of the image whose thumbnail to get"),
) -> FileResponse:
"""Gets a thumbnail"""
2023-05-21 12:15:44 +00:00
try:
path = ApiDependencies.invoker.services.images_new.get_path(
image_type=image_type, image_name=image_name, thumbnail=True
)
return FileResponse(path)
2023-05-21 12:15:44 +00:00
except Exception as e:
raise HTTPException(status_code=404)